Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56e11c86 authored by Raj Yengisetty's avatar Raj Yengisetty
Browse files

Protected Apps: Show state by component instead of by app

Change-Id: Idbe1d69b376fc3f42980404d9448152f606e7f8e
parent e4e34d2f
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
@@ -30,6 +29,7 @@ import com.android.settings.cyanogenmod.ProtectedAppsReceiver;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@@ -50,6 +50,8 @@ public class ProtectedAppsActivity extends Activity {

    private boolean mWaitUserAuth = false;

    private HashSet<ComponentName> mProtectedApps = new HashSet<ComponentName>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -92,6 +94,23 @@ public class ProtectedAppsActivity extends Activity {
        refreshAppsTask.execute(null, null, null);

        getActionBar().setDisplayHomeAsUpEnabled(true);

        // Update Protected Apps list
        updateProtectedComponentsList();
    }

    private void updateProtectedComponentsList() {
        String protectedComponents = Settings.Secure.getString(getContentResolver(),
                Settings.Secure.PROTECTED_COMPONENTS);
        protectedComponents = protectedComponents == null ? "" : protectedComponents;
        String [] flattened = protectedComponents.split("\\|");
        mProtectedApps = new HashSet<ComponentName>(flattened.length);
        for (String flat : flattened) {
            ComponentName cmp = ComponentName.unflattenFromString(flat);
            if (cmp != null) {
                mProtectedApps.add(cmp);
            }
        }
    }

    @Override
@@ -105,13 +124,7 @@ public class ProtectedAppsActivity extends Activity {
    }

    private boolean getProtectedStateFromComponentName(ComponentName componentName) {
        PackageManager pm = getPackageManager();

        try {
            return pm.getApplicationInfo(componentName.getPackageName(), 0).protect;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
        return mProtectedApps.contains(componentName);
    }

    @Override
@@ -263,6 +276,7 @@ public class ProtectedAppsActivity extends Activity {
                        appList.componentNames, appList.state);
            }

            updateProtectedComponentsList();
            return null;
        }
    }