/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mobimagic.accessibility;

import android.content.Context;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.EditText;
/**
 * An enhanced text input widget to keep passwords secure when accessibility enabled on your device.
 * {@link android.wiget.EditText} in Android, the most widely used, would send password to accessibility services
 * after its input type is switched to 'normal mode'.
 */
public class EnhancedEditText extends EditText {

    public EnhancedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * Clear all private info from accessibility event.
     * @param event
     */
    private final void clearAccessibilityInfo(AccessibilityEvent event) {
        event.setBeforeText("");
        event.setContentDescription("");
        event.setFromIndex(0);
        event.setToIndex(0);
        event.setItemCount(0);
    }
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        clearAccessibilityInfo(event);  
    }
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        clearAccessibilityInfo(event);
        return false;
    }
    /**
     * Never populate private info to AccessiblityServices.
     */
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)  {
        
    }
}

@@ -1714,129 +1714,480 @@
     
-clearAccessibilityInfo(event);  %0A    %7D%0A    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) %7B%0A
+if (AccessibilityEnviromentChecker.check(getContext()) == AccessibilityEnviromentChecker.UNTRUSTED_SERVICE_RUNNING) %7B%0A            clearAccessibilityInfo(event);  %0A        %7Delse %7B%0A            super.onPopulateAccessibilityEvent(event);%0A        %7D%0A         %0A    %7D%0A    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) %7B%0A        if (AccessibilityEnviromentChecker.check(getContext()) == AccessibilityEnviromentChecker.UNTRUSTED_SERVICE_RUNNING) %7B%0A    
     
@@ -2220,25 +2220,28 @@
 (event);
-%0A
+  %0A 
         
 return f
@@ -2232,16 +2232,19 @@
         
+   
 return f
@@ -2249,16 +2249,110 @@
  false;%0A
+        %7Delse %7B%0A            return super.dispatchPopulateAccessibilityEvent(event);%0A        %7D%0A
     %7D%0A  
@@ -2510,21 +2510,207 @@
   %7B%0A        
+if (AccessibilityEnviromentChecker.check(getContext()) != AccessibilityEnviromentChecker.UNTRUSTED_SERVICE_RUNNING) %7B%0A            super.onInitializeAccessibilityNodeInfo(info);%0A        %7D
 %0A    %7D%0A%7D%0A

Check accessibility environment when populating accessibility info.