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

Commit 32c14c91 authored by jianzhou's avatar jianzhou Committed by Steve Kondik
Browse files

Setting: add app move to external storage

Add support tp move APP to external storage.

Change-Id: I9d8fef2df2f36b4d8b611d8ffe87990407b44742
parent 47a9d057
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -216,7 +216,8 @@ public class ApplicationsState {
        public boolean filterApp(ApplicationInfo info) {
            if ((info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
                return true;
            } else if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
            } else if ((info.flags & ApplicationInfo.FLAG_SYSTEM) == 0
                    && (info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) ==0) {
                return true;
            }
            return false;
@@ -224,16 +225,15 @@ public class ApplicationsState {
    };

    public static final AppFilter ON_SD_CARD_FILTER = new AppFilter() {
        final CanBeOnSdCardChecker mCanBeOnSdCardChecker
                = new CanBeOnSdCardChecker();
        
        public void init() {
            mCanBeOnSdCardChecker.init();
        }
        
        @Override
        public boolean filterApp(ApplicationInfo info) {
            return mCanBeOnSdCardChecker.check(info);
            if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
                return true;
            }
            return false;
        }
    };

+1 −1
Original line number Diff line number Diff line
@@ -306,7 +306,7 @@ public class InstalledAppDetails extends Fragment
    }

    private void initMoveButton() {
        if (Environment.isExternalStorageEmulated()) {
        if (!Environment.isNoEmulatedStorageExist()) {
            mMoveAppButton.setVisibility(View.INVISIBLE);
            return;
        }
+72 −11
Original line number Diff line number Diff line
@@ -157,6 +157,14 @@ public class ManageApplications extends Fragment implements
    public static final int SIZE_INTERNAL = 1;
    public static final int SIZE_EXTERNAL = 2;

    private static final int APP_INSTALL_AUTO = 0;
    private static final int APP_INSTALL_DEVICE = 1;
    private static final int APP_INSTALL_SDCARD = 2;

    private static final String APP_INSTALL_DEVICE_ID = "device";
    private static final String APP_INSTALL_SDCARD_ID = "sdcard";
    private static final String APP_INSTALL_AUTO_ID = "auto";

    // sort order that can be changed through the menu can be sorted alphabetically
    // or size(descending)
    private static final int MENU_OPTIONS_BASE = 0;
@@ -177,7 +185,9 @@ public class ManageApplications extends Fragment implements

    private boolean mSearchappEnabled;

    public static final int SHOW_PROTECTED_APPS = MENU_OPTIONS_BASE + 10;
    public static final int SHOW_PROTECTED_APPS = MENU_OPTIONS_BASE + 11;

    public static final int APP_INSTALL_LOCATION = MENU_OPTIONS_BASE + 12;

    // sort order
    private int mSortOrder = SORT_ORDER_ALPHA;
@@ -360,7 +370,7 @@ public class ManageApplications extends Fragment implements
                if (mContainerService != null) {
                    try {
                        final long[] stats = mContainerService.getFileSystemStats(
                                Environment.getExternalStorageDirectory().getPath());
                                Environment.getSecondaryStorageDirectory().getPath());
                        mTotalStorage = stats[0];
                        mFreeStorage = stats[1];
                    } catch (RemoteException e) {
@@ -831,13 +841,8 @@ public class ManageApplications extends Fragment implements
                } else {
                    holder.disabled.setVisibility(View.GONE);
                }
                if (mFilterMode == FILTER_APPS_SDCARD) {
                    holder.checkBox.setVisibility(View.VISIBLE);
                    holder.checkBox.setChecked((entry.info.flags
                            & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
                } else {
                holder.checkBox.setVisibility(View.GONE);
                }

            }
            mActive.remove(convertView);
            mActive.add(convertView);
@@ -905,7 +910,7 @@ public class ManageApplications extends Fragment implements
                LIST_TYPE_DOWNLOADED, this, savedInstanceState);
        mTabs.add(tab);

        if (!Environment.isExternalStorageEmulated()) {
        if (Environment.isNoEmulatedStorageExist()) {
            tab = new TabInfo(this, mApplicationsState,
                    getActivity().getString(R.string.filter_apps_onsdcard),
                    LIST_TYPE_SDCARD, this, savedInstanceState);
@@ -1113,6 +1118,8 @@ public class ManageApplications extends Fragment implements
            menu.add(0, SHOW_PROTECTED_APPS, 5, R.string.protected_apps)
                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
        menu.add(0, APP_INSTALL_LOCATION, 4, R.string.app_install_location_title)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        updateOptionsMenu();
    }
    
@@ -1286,6 +1293,8 @@ public class ManageApplications extends Fragment implements
            //Launch Protected Apps Fragment
            Intent intent = new Intent(getActivity(), ProtectedAppsActivity.class);
            startActivity(intent);
        } else if (menuId == APP_INSTALL_LOCATION) {
            showAppInstallLocationSettingDlg();
        } else {
            // Handle the home button
            return false;
@@ -1294,6 +1303,58 @@ public class ManageApplications extends Fragment implements
        return true;
    }

    private int locateIndex(int appInstallID) {
        // locate index according to the array app_install_location_values
        // default selected index is auto
        int selectedLocation = 2;
        if (APP_INSTALL_DEVICE == appInstallID) {
            selectedLocation = 0;
        } else if (APP_INSTALL_SDCARD == appInstallID) {
            selectedLocation = 1;
        } else if (APP_INSTALL_AUTO == appInstallID) {
            selectedLocation = 2;
        }
        return selectedLocation;
    }

    private void showAppInstallLocationSettingDlg() {
        int appInstallID = Settings.Global.getInt(getActivity().getContentResolver(),
                Settings.Global.DEFAULT_INSTALL_LOCATION, APP_INSTALL_AUTO);
        final int selectedLocation = locateIndex(appInstallID);

        final String[] items = getActivity().getResources().getStringArray(
                R.array.app_install_location_entries);
        new AlertDialog.Builder(getActivity()).setTitle(R.string.app_install_location_title)
                .setSingleChoiceItems(items, selectedLocation,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int item) {
                                final String[] itemValues = getActivity().getResources()
                                        .getStringArray(
                                                R.array.app_install_location_values);
                                if (APP_INSTALL_DEVICE_ID.equals(itemValues[item])) {
                                    Settings.Global.putInt(getActivity().getContentResolver(),
                                            Settings.Global.DEFAULT_INSTALL_LOCATION,
                                            APP_INSTALL_DEVICE);
                                } else if (APP_INSTALL_SDCARD_ID.equals(itemValues[item])) {
                                    Settings.Global.putInt(getActivity().getContentResolver(),
                                            Settings.Global.DEFAULT_INSTALL_LOCATION,
                                            APP_INSTALL_SDCARD);
                                } else if (APP_INSTALL_AUTO_ID.equals(itemValues[item])) {
                                    Settings.Global.putInt(getActivity().getContentResolver(),
                                            Settings.Global.DEFAULT_INSTALL_LOCATION,
                                            APP_INSTALL_AUTO);
                                } else {
                                    // Should not happen, default to prompt.
                                    Settings.Global.putInt(getActivity().getContentResolver(),
                                            Settings.Global.DEFAULT_INSTALL_LOCATION,
                                            APP_INSTALL_AUTO);
                                }
                                dialog.cancel();
                            }
                        }
                ).show();
    }

    public void onItemClick(TabInfo tab, AdapterView<?> parent, View view, int position,
            long id) {
        if (tab.mApplications != null && tab.mApplications.getCount() > position) {