DO NOT MERGE : Move some system services to their own sub package.

(Cherry pick from master)

As a next step they can be moved into separate directories to be
built as separate modules that may or may not be included in a
particular configuration.

Moves AppWidgetService, BackupManagerService, ClipboardService, DevicePolicyMS,
and WallpaperMS.

Change-Id: Idd92871c1828bdde81d85fe99a9c87a22d53169d
This commit is contained in:
Amith Yamasani
2013-11-06 14:54:50 -08:00
committed by Mike Lockwood
parent d50d41e4df
commit 09e9cdcece
13 changed files with 80 additions and 35 deletions

View File

@@ -71,4 +71,14 @@ interface IWallpaperManager {
* Returns the desired minimum height for the wallpaper. * Returns the desired minimum height for the wallpaper.
*/ */
int getHeightHint(); int getHeightHint();
/**
* Returns the name of the wallpaper. Private API.
*/
String getName();
/**
* Informs the service that wallpaper settings have been restored. Private API.
*/
void settingsRestored();
} }

View File

@@ -2522,7 +2522,7 @@
android:hasCode="false" android:hasCode="false"
android:label="@string/android_system_label" android:label="@string/android_system_label"
android:allowClearUserData="false" android:allowClearUserData="false"
android:backupAgent="com.android.server.SystemBackupAgent" android:backupAgent="com.android.server.backup.SystemBackupAgent"
android:killAfterRestore="false" android:killAfterRestore="false"
android:icon="@drawable/ic_launcher_android" android:icon="@drawable/ic_launcher_android"
android:supportsRtl="true"> android:supportsRtl="true">

View File

@@ -51,7 +51,11 @@ import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accounts.AccountManagerService; import com.android.server.accounts.AccountManagerService;
import com.android.server.am.ActivityManagerService; import com.android.server.am.ActivityManagerService;
import com.android.server.am.BatteryStatsService; import com.android.server.am.BatteryStatsService;
import com.android.server.appwidget.AppWidgetService;
import com.android.server.backup.BackupManagerService;
import com.android.server.clipboard.ClipboardService;
import com.android.server.content.ContentService; import com.android.server.content.ContentService;
import com.android.server.devicepolicy.DevicePolicyManagerService;
import com.android.server.display.DisplayManagerService; import com.android.server.display.DisplayManagerService;
import com.android.server.dreams.DreamManagerService; import com.android.server.dreams.DreamManagerService;
import com.android.server.input.InputManagerService; import com.android.server.input.InputManagerService;
@@ -67,6 +71,7 @@ import com.android.server.power.ShutdownThread;
import com.android.server.print.PrintManagerService; import com.android.server.print.PrintManagerService;
import com.android.server.search.SearchManagerService; import com.android.server.search.SearchManagerService;
import com.android.server.usb.UsbService; import com.android.server.usb.UsbService;
import com.android.server.wallpaper.WallpaperManagerService;
import com.android.server.wifi.WifiService; import com.android.server.wifi.WifiService;
import com.android.server.wm.WindowManagerService; import com.android.server.wm.WindowManagerService;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.appwidget;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.appwidget.AppWidgetProviderInfo; import android.appwidget.AppWidgetProviderInfo;
@@ -48,7 +48,7 @@ import java.util.Locale;
/** /**
* Redirects calls to this service to the instance of the service for the appropriate user. * Redirects calls to this service to the instance of the service for the appropriate user.
*/ */
class AppWidgetService extends IAppWidgetService.Stub public class AppWidgetService extends IAppWidgetService.Stub
{ {
private static final String TAG = "AppWidgetService"; private static final String TAG = "AppWidgetService";
@@ -60,7 +60,7 @@ class AppWidgetService extends IAppWidgetService.Stub
private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices; private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
AppWidgetService(Context context) { public AppWidgetService(Context context) {
mContext = context; mContext = context;
mSaveStateHandler = BackgroundThread.getHandler(); mSaveStateHandler = BackgroundThread.getHandler();

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.appwidget;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.AppGlobals; import android.app.AppGlobals;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.backup;
import android.app.ActivityManagerNative; import android.app.ActivityManagerNative;
import android.app.AlarmManager; import android.app.AlarmManager;
@@ -83,7 +83,8 @@ import com.android.internal.backup.BackupConstants;
import com.android.internal.backup.IBackupTransport; import com.android.internal.backup.IBackupTransport;
import com.android.internal.backup.IObbBackupService; import com.android.internal.backup.IObbBackupService;
import com.android.internal.backup.LocalTransport; import com.android.internal.backup.LocalTransport;
import com.android.server.PackageManagerBackupAgent.Metadata; import com.android.server.EventLogTags;
import com.android.server.backup.PackageManagerBackupAgent.Metadata;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@@ -135,7 +136,7 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
class BackupManagerService extends IBackupManager.Stub { public class BackupManagerService extends IBackupManager.Stub {
private static final String TAG = "BackupManagerService"; private static final String TAG = "BackupManagerService";
private static final boolean DEBUG = true; private static final boolean DEBUG = true;
private static final boolean MORE_DEBUG = false; private static final boolean MORE_DEBUG = false;
@@ -1178,7 +1179,8 @@ class BackupManagerService extends IBackupManager.Stub {
// First, on an encrypted device we require matching the device pw // First, on an encrypted device we require matching the device pw
final boolean isEncrypted; final boolean isEncrypted;
try { try {
isEncrypted = (mMountService.getEncryptionState() != MountService.ENCRYPTION_STATE_NONE); isEncrypted = (mMountService.getEncryptionState() !=
IMountService.ENCRYPTION_STATE_NONE);
if (isEncrypted) { if (isEncrypted) {
if (DEBUG) { if (DEBUG) {
Slog.i(TAG, "Device encrypted; verifying against device data pw"); Slog.i(TAG, "Device encrypted; verifying against device data pw");
@@ -5437,7 +5439,8 @@ class BackupManagerService extends IBackupManager.Stub {
boolean isEncrypted; boolean isEncrypted;
try { try {
isEncrypted = (mMountService.getEncryptionState() != MountService.ENCRYPTION_STATE_NONE); isEncrypted = (mMountService.getEncryptionState() !=
IMountService.ENCRYPTION_STATE_NONE);
if (isEncrypted) Slog.w(TAG, "Device is encrypted; forcing enc password"); if (isEncrypted) Slog.w(TAG, "Device is encrypted; forcing enc password");
} catch (RemoteException e) { } catch (RemoteException e) {
// couldn't contact the mount service; fail "safe" and assume encryption // couldn't contact the mount service; fail "safe" and assume encryption

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.backup;
import android.app.backup.BackupAgent; import android.app.backup.BackupAgent;
import android.app.backup.BackupDataInput; import android.app.backup.BackupDataInput;

View File

@@ -14,9 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.backup;
import android.app.IWallpaperManager;
import android.app.backup.BackupDataInput; import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput; import android.app.backup.BackupDataOutput;
import android.app.backup.BackupAgentHelper; import android.app.backup.BackupAgentHelper;
@@ -26,11 +27,11 @@ import android.app.backup.WallpaperBackupHelper;
import android.content.Context; import android.content.Context;
import android.os.Environment; import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Slog; import android.util.Slog;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -63,17 +64,24 @@ public class SystemBackupAgent extends BackupAgentHelper {
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException { ParcelFileDescriptor newState) throws IOException {
// We only back up the data under the current "wallpaper" schema with metadata // We only back up the data under the current "wallpaper" schema with metadata
WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService( IWallpaperManager wallpaper = (IWallpaperManager)ServiceManager.getService(
Context.WALLPAPER_SERVICE); Context.WALLPAPER_SERVICE);
String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO }; String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO };
String[] keys = new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY }; String[] keys = new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY };
if (wallpaper != null && wallpaper.getName() != null && wallpaper.getName().length() > 0) { if (wallpaper != null) {
try {
final String wallpaperName = wallpaper.getName();
if (wallpaperName != null && wallpaperName.length() > 0) {
// When the wallpaper has a name, back up the info by itself. // When the wallpaper has a name, back up the info by itself.
// TODO: Don't rely on the innards of the service object like this! // TODO: Don't rely on the innards of the service object like this!
// TODO: Send a delete for any stored wallpaper image in this case? // TODO: Send a delete for any stored wallpaper image in this case?
files = new String[] { WALLPAPER_INFO }; files = new String[] { WALLPAPER_INFO };
keys = new String[] { WALLPAPER_INFO_KEY }; keys = new String[] { WALLPAPER_INFO_KEY };
} }
} catch (RemoteException re) {
Slog.e(TAG, "Couldn't get wallpaper name\n" + re);
}
}
addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files, keys)); addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files, keys));
super.onBackup(oldState, data, newState); super.onBackup(oldState, data, newState);
} }
@@ -109,9 +117,15 @@ public class SystemBackupAgent extends BackupAgentHelper {
try { try {
super.onRestore(data, appVersionCode, newState); super.onRestore(data, appVersionCode, newState);
WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService( IWallpaperManager wallpaper = (IWallpaperManager) ServiceManager.getService(
Context.WALLPAPER_SERVICE); Context.WALLPAPER_SERVICE);
if (wallpaper != null) {
try {
wallpaper.settingsRestored(); wallpaper.settingsRestored();
} catch (RemoteException re) {
Slog.e(TAG, "Couldn't restore settings\n" + re);
}
}
} catch (IOException ex) { } catch (IOException ex) {
// If there was a failure, delete everything for the wallpaper, this is too aggressive, // If there was a failure, delete everything for the wallpaper, this is too aggressive,
// but this is hopefully a rare failure. // but this is hopefully a rare failure.
@@ -149,10 +163,16 @@ public class SystemBackupAgent extends BackupAgentHelper {
FullBackup.restoreFile(data, size, type, mode, mtime, outFile); FullBackup.restoreFile(data, size, type, mode, mtime, outFile);
if (restoredWallpaper) { if (restoredWallpaper) {
WallpaperManagerService wallpaper = IWallpaperManager wallpaper =
(WallpaperManagerService)ServiceManager.getService( (IWallpaperManager)ServiceManager.getService(
Context.WALLPAPER_SERVICE); Context.WALLPAPER_SERVICE);
if (wallpaper != null) {
try {
wallpaper.settingsRestored(); wallpaper.settingsRestored();
} catch (RemoteException re) {
Slog.e(TAG, "Couldn't restore settings\n" + re);
}
}
} }
} catch (IOException e) { } catch (IOException e) {
if (restoredWallpaper) { if (restoredWallpaper) {

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.clipboard;
import android.app.ActivityManagerNative; import android.app.ActivityManagerNative;
import android.app.AppGlobals; import android.app.AppGlobals;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.devicepolicy;
import static android.Manifest.permission.MANAGE_CA_CERTIFICATES; import static android.Manifest.permission.MANAGE_CA_CERTIFICATES;

View File

@@ -17,7 +17,6 @@
package com.android.server.pm; package com.android.server.pm;
import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils;
import com.android.server.PreferredComponent;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.pm;
import com.android.internal.util.XmlUtils; import com.android.internal.util.XmlUtils;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server; package com.android.server.wallpaper;
import static android.os.ParcelFileDescriptor.*; import static android.os.ParcelFileDescriptor.*;
@@ -85,8 +85,8 @@ import com.android.internal.content.PackageMonitor;
import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.JournaledFile; import com.android.internal.util.JournaledFile;
class WallpaperManagerService extends IWallpaperManager.Stub { public class WallpaperManagerService extends IWallpaperManager.Stub {
static final String TAG = "WallpaperService"; static final String TAG = "WallpaperManagerService";
static final boolean DEBUG = false; static final boolean DEBUG = false;
final Object mLock = new Object[0]; final Object mLock = new Object[0];
@@ -98,7 +98,6 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
static final long MIN_WALLPAPER_CRASH_TIME = 10000; static final long MIN_WALLPAPER_CRASH_TIME = 10000;
static final String WALLPAPER = "wallpaper"; static final String WALLPAPER = "wallpaper";
static final String WALLPAPER_INFO = "wallpaper_info.xml"; static final String WALLPAPER_INFO = "wallpaper_info.xml";
/** /**
* Name of the component used to display bitmap wallpapers from either the gallery or * Name of the component used to display bitmap wallpapers from either the gallery or
* built-in wallpapers. * built-in wallpapers.
@@ -505,7 +504,12 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
} }
} }
String getName() { /** Called by SystemBackupAgent */
public String getName() {
// Verify caller is the system
if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
throw new RuntimeException("getName() can only be called from the system process");
}
synchronized (mLock) { synchronized (mLock) {
return mWallpaperMap.get(0).name; return mWallpaperMap.get(0).name;
} }
@@ -1175,7 +1179,11 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
} }
// Called by SystemBackupAgent after files are restored to disk. // Called by SystemBackupAgent after files are restored to disk.
void settingsRestored() { public void settingsRestored() {
// Verify caller is the system
if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
throw new RuntimeException("settingsRestored() can only be called from the system process");
}
// TODO: If necessary, make it work for secondary users as well. This currently assumes // TODO: If necessary, make it work for secondary users as well. This currently assumes
// restores only to the primary user // restores only to the primary user
if (DEBUG) Slog.v(TAG, "settingsRestored"); if (DEBUG) Slog.v(TAG, "settingsRestored");