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

Commit c2461be6 authored by Suchi Amalapurapu's avatar Suchi Amalapurapu Committed by Android (Google) Code Review
Browse files

Merge "Fix 2579461 Move install location values to secure settings. Diable...

Merge "Fix 2579461 Move install location values to secure settings. Diable attribute for UI. Set default value to auto. Add command line interface to set install location via pm." into froyo
parents ce59fb8b 40e47252
Loading
Loading
Loading
Loading
+69 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.commands.pm;

import com.android.internal.content.PackageHelper;

import android.content.ComponentName;
import android.content.pm.ApplicationInfo;
import android.content.pm.FeatureInfo;
@@ -33,6 +35,7 @@ import android.content.res.Resources;
import android.net.Uri;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;

import java.io.File;
import java.lang.reflect.Field;
@@ -107,6 +110,16 @@ public final class Pm {
            return;
        }

        if ("setInstallLocation".equals(op)) {
            runSetInstallLocation();
            return;
        }

        if ("getInstallLocation".equals(op)) {
            runGetInstallLocation();
            return;
        }

        try {
            if (args.length == 1) {
                if (args[0].equalsIgnoreCase("-l")) {
@@ -575,6 +588,51 @@ public final class Pm {
        return Integer.toString(result);
    }

    private void runSetInstallLocation() {
        int loc;

        String arg = nextArg();
        if (arg == null) {
            System.err.println("Error: no install location specified.");
            showUsage();
            return;
        }
        try {
            loc = Integer.parseInt(arg);
        } catch (NumberFormatException e) {
            System.err.println("Error: install location has to be a number.");
            showUsage();
            return;
        }
        try {
            if (!mPm.setInstallLocation(loc)) {
                System.err.println("Error: install location has to be a number.");
                showUsage();
            }
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(PM_NOT_RUNNING_ERR);
        }
    }

    private void runGetInstallLocation() {
        try {
            int loc = mPm.getInstallLocation();
            String locStr = "invalid";
            if (loc == PackageHelper.APP_INSTALL_AUTO) {
                locStr = "auto";
            } else if (loc == PackageHelper.APP_INSTALL_INTERNAL) {
                locStr = "internal";
            } else if (loc == PackageHelper.APP_INSTALL_EXTERNAL) {
                locStr = "external";
            }
            System.out.println(loc + "[" + locStr + "]");
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(PM_NOT_RUNNING_ERR);
        }
    }

    private void runInstall() {
        int installFlags = 0;
        String installerPackageName = null;
@@ -832,6 +890,7 @@ public final class Pm {
        System.err.println("       pm uninstall [-k] PACKAGE");
        System.err.println("       pm enable PACKAGE_OR_COMPONENT");
        System.err.println("       pm disable PACKAGE_OR_COMPONENT");
        System.err.println("       pm setInstallLocation [0/auto] [1/internal] [2/external]");
        System.err.println("");
        System.err.println("The list packages command prints all packages.  Options:");
        System.err.println("  -f: see their associated file.");
@@ -867,10 +926,17 @@ public final class Pm {
        System.err.println("  -k: keep the data and cache directories around.");
        System.err.println("after the package removal.");
        System.err.println("");
        System.err.println("The mountsd command simulates mounting/unmounting sdcard.Options:");
        System.err.println("  -m: true or false.");
        System.err.println("");
        System.err.println("The enable and disable commands change the enabled state of");
        System.err.println("a given package or component (written as \"package/class\").");
        System.err.println("");
        System.err.println("The getInstallLocation command gets the current install location");
        System.err.println("  0 [auto]: Let system decide the best location");
        System.err.println("  1 [internal]: Install on internal device storage");
        System.err.println("  2 [external]: Install on external media");
        System.err.println("");
        System.err.println("The setInstallLocation command changes the default install location");
        System.err.println("  0 [auto]: Let system decide the best location");
        System.err.println("  1 [internal]: Install on internal device storage");
        System.err.println("  2 [external]: Install on external media");
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -316,4 +316,7 @@ interface IPackageManager {
    void movePackage(String packageName, IPackageMoveObserver observer, int flags);
    
    boolean addPermissionAsync(in PermissionInfo info);

    boolean setInstallLocation(int loc);
    int getInstallLocation();
}
+15 −15
Original line number Diff line number Diff line
@@ -1610,21 +1610,6 @@ public final class Settings {
         */
        public static final String NOTIFICATION_LIGHT_PULSE = "notification_light_pulse";

        /**
         * Let user pick default install location.
         * @hide
         */
        public static final String SET_INSTALL_LOCATION = "set_install_location";

        /**
         * Default install location value.
         * 0 = auto, let system decide
         * 1 = internal
         * 2 = sdcard
         * @hide
         */
        public static final String DEFAULT_INSTALL_LOCATION = "default_install_location";

        /**
         * Show pointer location on screen?
         * 0 = no
@@ -3296,6 +3281,21 @@ public final class Settings {
         */
        public static final String UI_NIGHT_MODE = "ui_night_mode";

        /**
         * Let user pick default install location.
         * @hide
         */
        public static final String SET_INSTALL_LOCATION = "set_install_location";

        /**
         * Default install location value.
         * 0 = auto, let system decide
         * 1 = internal
         * 2 = sdcard
         * @hide
         */
        public static final String DEFAULT_INSTALL_LOCATION = "default_install_location";
        
        /**
         * @hide
         */
+7 −7
Original line number Diff line number Diff line
@@ -328,14 +328,14 @@ public class PackageManagerTests extends AndroidTestCase {
        boolean checkSd = false;
        int setLoc = 0;
        try {
            setLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.System.SET_INSTALL_LOCATION);
            setLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION);
        } catch (SettingNotFoundException e) {
            failStr(e);
        }
        if (setLoc == 1) {
            int userPref = APP_INSTALL_AUTO;
            try {
                userPref = Settings.System.getInt(mContext.getContentResolver(), Settings.System.DEFAULT_INSTALL_LOCATION);
                userPref = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.DEFAULT_INSTALL_LOCATION);
            } catch (SettingNotFoundException e) {
                failStr(e);
            }
@@ -1302,8 +1302,8 @@ public class PackageManagerTests extends AndroidTestCase {
        boolean userSetting = false;
        int origDefaultLoc = PackageInfo.INSTALL_LOCATION_AUTO;
        try {
            userSetting = Settings.System.getInt(mContext.getContentResolver(), Settings.System.SET_INSTALL_LOCATION) != 0;
            origDefaultLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.System.DEFAULT_INSTALL_LOCATION);
            userSetting = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION) != 0;
            origDefaultLoc = Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.DEFAULT_INSTALL_LOCATION);
        } catch (SettingNotFoundException e1) {
        }
        return origDefaultLoc;
@@ -1311,7 +1311,7 @@ public class PackageManagerTests extends AndroidTestCase {

    private void setInstallLoc(int loc) {
        Settings.System.putInt(mContext.getContentResolver(),
                Settings.System.DEFAULT_INSTALL_LOCATION, loc);
                Settings.Secure.DEFAULT_INSTALL_LOCATION, loc);
    }
    /*
     * Tests for moving apps between internal and external storage
@@ -1963,7 +1963,7 @@ public class PackageManagerTests extends AndroidTestCase {
    */
   private boolean getUserSettingSetInstallLocation() {
       try {
           return Settings.System.getInt(mContext.getContentResolver(), Settings.System.SET_INSTALL_LOCATION) != 0;
           return Settings.System.getInt(mContext.getContentResolver(), Settings.Secure.SET_INSTALL_LOCATION) != 0;
           
       } catch (SettingNotFoundException e1) {
       }
@@ -1972,7 +1972,7 @@ public class PackageManagerTests extends AndroidTestCase {

   private void setUserSettingSetInstallLocation(boolean value) {
       Settings.System.putInt(mContext.getContentResolver(),
               Settings.System.SET_INSTALL_LOCATION, value ? 1 : 0);
               Settings.Secure.SET_INSTALL_LOCATION, value ? 1 : 0);
   }
   private void setUserX(boolean enable, int userSetting, int iloc) {
       boolean origUserSetting = getUserSettingSetInstallLocation();
+12 −18
Original line number Diff line number Diff line
@@ -339,15 +339,10 @@ public class DefaultContainerService extends IntentService {
                checkBoth = true;
                break check_inner;
            }
            // Check if user option is enabled
            boolean setInstallLoc = Settings.System.getInt(getApplicationContext()
                    .getContentResolver(),
                    Settings.System.SET_INSTALL_LOCATION, 0) != 0;
            if (setInstallLoc) {
            // Pick user preference
            int installPreference = Settings.System.getInt(getApplicationContext()
                    .getContentResolver(),
                        Settings.System.DEFAULT_INSTALL_LOCATION,
                    Settings.Secure.DEFAULT_INSTALL_LOCATION,
                    PackageHelper.APP_INSTALL_AUTO);
            if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
                checkInt = true;
@@ -358,7 +353,6 @@ public class DefaultContainerService extends IntentService {
                checkBoth = true;
                break check_inner;
            }
            }
            // Fall back to default policy if nothing else is specified.
            checkInt = true;
            checkBoth = true;
Loading