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.
*/
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:label="@string/android_system_label"
android:allowClearUserData="false"
android:backupAgent="com.android.server.SystemBackupAgent"
android:backupAgent="com.android.server.backup.SystemBackupAgent"
android:killAfterRestore="false"
android:icon="@drawable/ic_launcher_android"
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.am.ActivityManagerService;
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.devicepolicy.DevicePolicyManagerService;
import com.android.server.display.DisplayManagerService;
import com.android.server.dreams.DreamManagerService;
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.search.SearchManagerService;
import com.android.server.usb.UsbService;
import com.android.server.wallpaper.WallpaperManagerService;
import com.android.server.wifi.WifiService;
import com.android.server.wm.WindowManagerService;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.server;
package com.android.server.appwidget;
import android.app.ActivityManager;
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.
*/
class AppWidgetService extends IAppWidgetService.Stub
public class AppWidgetService extends IAppWidgetService.Stub
{
private static final String TAG = "AppWidgetService";
@ -60,7 +60,7 @@ class AppWidgetService extends IAppWidgetService.Stub
private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
AppWidgetService(Context context) {
public AppWidgetService(Context context) {
mContext = context;
mSaveStateHandler = BackgroundThread.getHandler();

View File

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

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.server;
package com.android.server.backup;
import android.app.ActivityManagerNative;
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.IObbBackupService;
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.BufferedOutputStream;
@ -135,7 +136,7 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
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 boolean DEBUG = true;
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
final boolean isEncrypted;
try {
isEncrypted = (mMountService.getEncryptionState() != MountService.ENCRYPTION_STATE_NONE);
isEncrypted = (mMountService.getEncryptionState() !=
IMountService.ENCRYPTION_STATE_NONE);
if (isEncrypted) {
if (DEBUG) {
Slog.i(TAG, "Device encrypted; verifying against device data pw");
@ -5437,7 +5439,8 @@ class BackupManagerService extends IBackupManager.Stub {
boolean isEncrypted;
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");
} catch (RemoteException e) {
// couldn't contact the mount service; fail "safe" and assume encryption

View File

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

View File

@ -14,9 +14,10 @@
* 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.BackupDataOutput;
import android.app.backup.BackupAgentHelper;
@ -26,11 +27,11 @@ import android.app.backup.WallpaperBackupHelper;
import android.content.Context;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.Slog;
import java.io.File;
import java.io.IOException;
@ -63,16 +64,23 @@ public class SystemBackupAgent extends BackupAgentHelper {
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
// 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);
String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO };
String[] keys = new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY };
if (wallpaper != null && wallpaper.getName() != null && wallpaper.getName().length() > 0) {
// 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: Send a delete for any stored wallpaper image in this case?
files = new String[] { WALLPAPER_INFO };
keys = new String[] { WALLPAPER_INFO_KEY };
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.
// 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?
files = new String[] { WALLPAPER_INFO };
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));
super.onBackup(oldState, data, newState);
@ -109,9 +117,15 @@ public class SystemBackupAgent extends BackupAgentHelper {
try {
super.onRestore(data, appVersionCode, newState);
WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService(
IWallpaperManager wallpaper = (IWallpaperManager) ServiceManager.getService(
Context.WALLPAPER_SERVICE);
wallpaper.settingsRestored();
if (wallpaper != null) {
try {
wallpaper.settingsRestored();
} catch (RemoteException re) {
Slog.e(TAG, "Couldn't restore settings\n" + re);
}
}
} catch (IOException ex) {
// If there was a failure, delete everything for the wallpaper, this is too aggressive,
// but this is hopefully a rare failure.
@ -149,10 +163,16 @@ public class SystemBackupAgent extends BackupAgentHelper {
FullBackup.restoreFile(data, size, type, mode, mtime, outFile);
if (restoredWallpaper) {
WallpaperManagerService wallpaper =
(WallpaperManagerService)ServiceManager.getService(
IWallpaperManager wallpaper =
(IWallpaperManager)ServiceManager.getService(
Context.WALLPAPER_SERVICE);
wallpaper.settingsRestored();
if (wallpaper != null) {
try {
wallpaper.settingsRestored();
} catch (RemoteException re) {
Slog.e(TAG, "Couldn't restore settings\n" + re);
}
}
}
} catch (IOException e) {
if (restoredWallpaper) {

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.server;
package com.android.server.wallpaper;
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.JournaledFile;
class WallpaperManagerService extends IWallpaperManager.Stub {
static final String TAG = "WallpaperService";
public class WallpaperManagerService extends IWallpaperManager.Stub {
static final String TAG = "WallpaperManagerService";
static final boolean DEBUG = false;
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 String WALLPAPER = "wallpaper";
static final String WALLPAPER_INFO = "wallpaper_info.xml";
/**
* Name of the component used to display bitmap wallpapers from either the gallery or
* 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) {
return mWallpaperMap.get(0).name;
}
@ -1175,7 +1179,11 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
}
// 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
// restores only to the primary user
if (DEBUG) Slog.v(TAG, "settingsRestored");