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

Commit 9ee0a741 authored by Raj Yengisetty's avatar Raj Yengisetty Committed by Rajesh Yengisetty
Browse files

Protected Apps:

 - App Info for protected Apps doesn't allow Uninstall or Clear data
 - App Info menu item for launching into Protected Apps when looking at protected components
 - Prevent process dialog from getting dismissed on touch or back key (can cause odd behavior if cancelled mid-protect)

Change-Id: I64104d7ff3fbf9d8c393ebf262d4de0b28abbc5c
parent 6c3bebd7
Loading
Loading
Loading
Loading
+461 B
Loading image diff...
+372 B
Loading image diff...
+601 B
Loading image diff...
+746 B
Loading image diff...
+66 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.applications;

import android.content.pm.ActivityInfo;
import com.android.internal.telephony.ISms;
import com.android.internal.telephony.SmsUsageMonitor;
import com.android.settings.R;
@@ -85,6 +86,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import com.android.settings.cyanogenmod.ProtectedAppsReceiver;

/**
 * Activity to display application information from Settings. This activity presents
@@ -100,7 +102,6 @@ public class InstalledAppDetails extends Fragment
        ApplicationsState.Callbacks {
    private static final String TAG="InstalledAppDetails";
    private static final boolean localLOGV = false;
    
    public static final String ARG_PACKAGE_NAME = "package";

    private PackageManager mPm;
@@ -189,10 +190,12 @@ public class InstalledAppDetails extends Fragment

    // Menu identifiers
    public static final int UNINSTALL_ALL_USERS_MENU = 1;
    public static final int OPEN_PROTECTED_APPS = 2;

    // Result code identifiers
    public static final int REQUEST_UNINSTALL = 1;
    public static final int REQUEST_MANAGE_SPACE = 2;
    public static final int REQUEST_TOGGLE_PROTECTION = 3;

    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
@@ -249,6 +252,7 @@ public class InstalledAppDetails extends Fragment
    }
    
    private void initDataButtons() {
        boolean enabled = false;
        // If the app doesn't have its own space management UI
        // And it's a system app that doesn't allow clearing user data or is an active admin
        // Then disable the Clear Data button.
@@ -258,7 +262,7 @@ public class InstalledAppDetails extends Fragment
                        == ApplicationInfo.FLAG_SYSTEM
                        || mDpm.packageHasActiveAdmins(mPackageInfo.packageName))) {
            mClearDataButton.setText(R.string.clear_user_data_text);
            mClearDataButton.setEnabled(false);
            enabled = false;
            mCanClearData = false;
        } else {
            if (mAppEntry.info.manageSpaceActivityName != null) {
@@ -266,6 +270,18 @@ public class InstalledAppDetails extends Fragment
            } else {
                mClearDataButton.setText(R.string.clear_user_data_text);
            }
            enabled = true;
        }

        // This is a protected app component.
        // You cannot clear data for a protected component
        if (mPackageInfo.applicationInfo.protect) {
            enabled = false;
        }

        mClearDataButton.setEnabled(enabled);
        mCanClearData = enabled;
        if (enabled) {
            mClearDataButton.setOnClickListener(this);
        }
    }
@@ -376,6 +392,12 @@ public class InstalledAppDetails extends Fragment
            enabled = false;
        }

        // This is a protected app component.
        // You cannot a uninstall a protected component
        if (mPackageInfo.applicationInfo.protect) {
            enabled = false;
        }

        // If this is the default (or only) home app, suppress uninstall (even if
        // we still think it should be allowed for other reasons)
        if (enabled && mHomePackages.contains(mPackageInfo.packageName)) {
@@ -514,6 +536,9 @@ public class InstalledAppDetails extends Fragment
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        menu.add(0, UNINSTALL_ALL_USERS_MENU, 1, R.string.uninstall_all_users_text)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(0, OPEN_PROTECTED_APPS, Menu.NONE, R.string.protected_apps)
                .setIcon(getResources().getDrawable(R.drawable.folder_lock))
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    @Override
@@ -533,6 +558,8 @@ public class InstalledAppDetails extends Fragment
            showIt = false;
        }
        menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(showIt);

        menu.findItem(OPEN_PROTECTED_APPS).setVisible(mPackageInfo.applicationInfo.protect);
    }

    @Override
@@ -541,6 +568,10 @@ public class InstalledAppDetails extends Fragment
        if (menuId == UNINSTALL_ALL_USERS_MENU) {
            uninstallPkg(mAppEntry.info.packageName, true, false);
            return true;
        } else if (menuId == OPEN_PROTECTED_APPS) {
            // Verify protection for toggling protected component status
            Intent protectedApps = new Intent(getActivity(), LockPatternActivity.class);
            startActivityForResult(protectedApps, REQUEST_TOGGLE_PROTECTION);
        }
        return false;
    }
@@ -566,6 +597,37 @@ public class InstalledAppDetails extends Fragment
            if (!refreshUi()) {
                setIntentAndFinish(true, true);
            }
        } else if (requestCode == REQUEST_TOGGLE_PROTECTION) {
            switch (resultCode) {
                case Activity.RESULT_OK:
                    new ToggleProtectedAppComponents().execute();
                    break;
                case Activity.RESULT_CANCELED:
                    // User failed to enter/confirm a lock pattern, do nothing
                    break;
            }
        }
    }
    private class ToggleProtectedAppComponents extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPostExecute(Void aVoid) {
            getActivity().invalidateOptionsMenu();
            if (!refreshUi()) {
                setIntentAndFinish(true, true);
            }
        }

        @Override
        protected Void doInBackground(Void... params) {
            String components = "";
            for (ActivityInfo aInfo : mPackageInfo.activities) {
                components += new ComponentName(aInfo.packageName, aInfo.name)
                        .flattenToString() + "|";
            }

            ProtectedAppsReceiver.protectedAppComponentsAndNotify
                    (components, true, getActivity());
            return null;
        }
    }

@@ -657,7 +719,8 @@ public class InstalledAppDetails extends Fragment
                mPackageInfo = mPm.getPackageInfo(mAppEntry.info.packageName,
                        PackageManager.GET_DISABLED_COMPONENTS |
                        PackageManager.GET_UNINSTALLED_PACKAGES |
                        PackageManager.GET_SIGNATURES);
                        PackageManager.GET_SIGNATURES |
                        PackageManager.GET_ACTIVITIES);
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Exception when retrieving package:" + mAppEntry.info.packageName, e);
            }
Loading