am 3e543abb: am a599469f: am c2461be6: 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

This commit is contained in:
Suchi Amalapurapu
2010-04-07 21:36:43 -07:00
committed by Android Git Automerger
8 changed files with 159 additions and 81 deletions

View File

@@ -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");
}
}

View File

@@ -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();
}

View File

@@ -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
@@ -3295,6 +3280,21 @@ public final class Settings {
* @hide
*/
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

View File

@@ -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();

View File

@@ -339,25 +339,19 @@ public class DefaultContainerService extends IntentService {
checkBoth = true;
break check_inner;
}
// Check if user option is enabled
boolean setInstallLoc = Settings.System.getInt(getApplicationContext()
// Pick user preference
int installPreference = 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,
PackageHelper.APP_INSTALL_AUTO);
if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
checkInt = true;
checkBoth = true;
break check_inner;
} else if (installPreference == PackageHelper.APP_INSTALL_EXTERNAL) {
checkExt = true;
checkBoth = true;
break check_inner;
}
Settings.Secure.DEFAULT_INSTALL_LOCATION,
PackageHelper.APP_INSTALL_AUTO);
if (installPreference == PackageHelper.APP_INSTALL_INTERNAL) {
checkInt = true;
checkBoth = true;
break check_inner;
} else if (installPreference == PackageHelper.APP_INSTALL_EXTERNAL) {
checkExt = true;
checkBoth = true;
break check_inner;
}
// Fall back to default policy if nothing else is specified.
checkInt = true;

View File

@@ -56,10 +56,6 @@
<bool name="def_mount_ums_autostart">false</bool>
<bool name="def_mount_ums_prompt">true</bool>
<bool name="def_mount_ums_notify_enabled">true</bool>
<!-- Enable User preference for setting install location -->
<bool name="set_install_location">true</bool>
<!-- Default install location if user preference for setting install location is turned on. -->
<integer name="def_install_location">2</integer>
<!-- user interface sound effects -->
<integer name="def_power_sounds_enabled">1</integer>

View File

@@ -39,6 +39,8 @@ import android.util.AttributeSet;
import android.util.Config;
import android.util.Log;
import android.util.Xml;
import com.android.internal.content.PackageHelper;
import com.android.internal.telephony.RILConstants;
import com.android.internal.util.XmlUtils;
import com.android.internal.widget.LockPatternUtils;
@@ -61,7 +63,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
// database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
// is properly propagated through your change. Not doing so will result in a loss of user
// settings.
private static final int DATABASE_VERSION = 55;
private static final int DATABASE_VERSION = 56;
private Context mContext;
@@ -608,21 +610,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
if (upgradeVersion == 50) {
/*
* New settings for set install location UI.
* Install location no longer initiated here.
*/
db.beginTransaction();
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT INTO system(name,value)"
+ " VALUES(?,?);");
loadBooleanSetting(stmt, Settings.System.SET_INSTALL_LOCATION,
R.bool.set_install_location);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (stmt != null) stmt.close();
}
upgradeVersion = 51;
}
@@ -663,21 +652,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
if (upgradeVersion == 53) {
/*
* New settings for set install location UI.
* New settings for set install location UI no longer initiated here.
*/
db.beginTransaction();
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT INTO system(name,value)"
+ " VALUES(?,?);");
loadIntegerSetting(stmt, Settings.System.DEFAULT_INSTALL_LOCATION,
R.integer.def_install_location);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (stmt != null) stmt.close();
}
upgradeVersion = 54;
}
@@ -696,6 +672,28 @@ public class DatabaseHelper extends SQLiteOpenHelper {
upgradeVersion = 55;
}
if (upgradeVersion == 55) {
/* Move the install location settings. */
String[] settingsToMove = {
Secure.SET_INSTALL_LOCATION,
Secure.DEFAULT_INSTALL_LOCATION
};
moveFromSystemToSecure(db, settingsToMove);
db.beginTransaction();
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT INTO system(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Secure.SET_INSTALL_LOCATION, 0);
loadSetting(stmt, Secure.DEFAULT_INSTALL_LOCATION,
PackageHelper.APP_INSTALL_AUTO);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (stmt != null) stmt.close();
}
upgradeVersion = 56;
}
// *** Remember to update DATABASE_VERSION above!
if (upgradeVersion != currentVersion) {
@@ -1021,10 +1019,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
R.bool.def_notification_pulse);
loadBooleanSetting(stmt, Settings.System.SET_INSTALL_LOCATION,
R.bool.set_install_location);
loadIntegerSetting(stmt, Settings.System.DEFAULT_INSTALL_LOCATION,
R.integer.def_install_location);
loadSetting(stmt, Settings.Secure.SET_INSTALL_LOCATION, 0);
loadSetting(stmt, Settings.Secure.DEFAULT_INSTALL_LOCATION,
PackageHelper.APP_INSTALL_AUTO);
loadUISoundEffectsSettings(stmt);

View File

@@ -31,8 +31,8 @@ import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.admin.IDevicePolicyManager;
import android.app.backup.IBackupManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
@@ -83,6 +83,7 @@ import android.os.Process;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings;
import android.security.SystemKeyStore;
import android.util.*;
import android.view.Display;
@@ -9857,5 +9858,26 @@ class PackageManagerService extends IPackageManager.Stub {
}
});
}
public boolean setInstallLocation(int loc) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.WRITE_SECURE_SETTINGS, null);
if (getInstallLocation() == loc) {
return true;
}
if (loc == PackageHelper.APP_INSTALL_AUTO ||
loc == PackageHelper.APP_INSTALL_INTERNAL ||
loc == PackageHelper.APP_INSTALL_EXTERNAL) {
android.provider.Settings.System.putInt(mContext.getContentResolver(),
android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, loc);
return true;
}
return false;
}
public int getInstallLocation() {
return android.provider.Settings.System.getInt(mContext.getContentResolver(),
android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, PackageHelper.APP_INSTALL_AUTO);
}
}