예제 #1
0
  private void removeUserStateLocked(final int userHandle) {
    // Cleanup package manager settings
    mPm.cleanUpUserLILPw(userHandle);

    // Remove this user from the list
    mUsers.remove(userHandle);

    // Have user ID linger for several seconds to let external storage VFS
    // cache entries expire. This must be greater than the 'entry_valid'
    // timeout used by the FUSE daemon.
    mHandler.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            synchronized (mPackagesLock) {
              mRemovingUserIds.delete(userHandle);
            }
          }
        },
        MINUTE_IN_MILLIS);

    // Remove user file
    AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml"));
    userFile.delete();
    // Update the user list
    writeUserListLocked();
    updateUserIdsLocked();
    removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle));
  }
예제 #2
0
  @Override
  public UserInfo createUser(String name, int flags) {
    checkManageUsersPermission("Only the system can create users");

    final long ident = Binder.clearCallingIdentity();
    final UserInfo userInfo;
    try {
      synchronized (mInstallLock) {
        synchronized (mPackagesLock) {
          if (isUserLimitReachedLocked()) return null;
          int userId = getNextAvailableIdLocked();
          userInfo = new UserInfo(userId, name, null, flags);
          File userPath = new File(mBaseUserPath, Integer.toString(userId));
          userInfo.serialNumber = mNextSerialNumber++;
          long now = System.currentTimeMillis();
          userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0;
          userInfo.partial = true;
          Environment.getUserSystemDirectory(userInfo.id).mkdirs();
          mUsers.put(userId, userInfo);
          writeUserListLocked();
          writeUserLocked(userInfo);
          mPm.createNewUserLILPw(userId, userPath);
          userInfo.partial = false;
          writeUserLocked(userInfo);
          updateUserIdsLocked();
        }
      }
      if (userInfo != null) {
        Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED);
        addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userInfo.id);
        mContext.sendBroadcastAsUser(
            addedIntent, UserHandle.ALL, android.Manifest.permission.MANAGE_USERS);
      }
    } finally {
      Binder.restoreCallingIdentity(ident);
    }
    return userInfo;
  }
public class WallpaperBackupHelper extends FileBackupHelperBase implements BackupHelper {

  private static final boolean DEBUG = false;
  private static final String STAGE_FILE =
      (new File(Environment.getUserSystemDirectory(0), "wallpaper-tmp")).getAbsolutePath();
  private static final String TAG = "WallpaperBackupHelper";
  public static final String WALLPAPER_IMAGE =
      (new File(Environment.getUserSystemDirectory(0), "wallpaper")).getAbsolutePath();
  public static final String WALLPAPER_IMAGE_KEY =
      "/data/data/com.android.settings/files/wallpaper";
  public static final String WALLPAPER_INFO =
      (new File(Environment.getUserSystemDirectory(0), "wallpaper_info.xml")).getAbsolutePath();
  public static final String WALLPAPER_INFO_KEY = "/data/system/wallpaper_info.xml";
  Context mContext;
  double mDesiredMinHeight;
  double mDesiredMinWidth;
  String mFiles[];
  String mKeys[];

  public WallpaperBackupHelper(Context context, String as[], String as1[]) {
    super(context);
    mContext = context;
    mFiles = as;
    mKeys = as1;
    WallpaperManager wallpapermanager = (WallpaperManager) context.getSystemService("wallpaper");
    mDesiredMinWidth = wallpapermanager.getDesiredMinimumWidth();
    mDesiredMinHeight = wallpapermanager.getDesiredMinimumHeight();
    if (mDesiredMinWidth <= 0.0D || mDesiredMinHeight <= 0.0D) {
      Display display = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
      Point point = new Point();
      display.getSize(point);
      mDesiredMinWidth = point.x;
      mDesiredMinHeight = point.y;
    }
  }

  public void performBackup(
      ParcelFileDescriptor parcelfiledescriptor,
      BackupDataOutput backupdataoutput,
      ParcelFileDescriptor parcelfiledescriptor1) {
    performBackup_checked(
        parcelfiledescriptor, backupdataoutput, parcelfiledescriptor1, mFiles, mKeys);
  }

  public void restoreEntity(BackupDataInputStream backupdatainputstream) {
    String s = backupdatainputstream.getKey();
    if (isKeyInList(s, mKeys))
      if (s.equals("/data/data/com.android.settings/files/wallpaper")) {
        File file = new File(STAGE_FILE);
        if (writeFile(file, backupdatainputstream)) {
          android.graphics.BitmapFactory.Options options =
              new android.graphics.BitmapFactory.Options();
          options.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(STAGE_FILE, options);
          double d = mDesiredMinWidth / (double) options.outWidth;
          double d1 = mDesiredMinHeight / (double) options.outHeight;
          if (d > 0.0D && d < 1.3300000000000001D && d1 > 0.0D && d1 < 1.3300000000000001D) {
            file.renameTo(new File(WALLPAPER_IMAGE));
          } else {
            file.delete();
            return;
          }
        }
      } else if (s.equals("/data/system/wallpaper_info.xml")) {
        writeFile(new File(WALLPAPER_INFO), backupdatainputstream);
        return;
      }
  }

  public volatile void writeNewStateDescription(ParcelFileDescriptor parcelfiledescriptor) {
    super.writeNewStateDescription(parcelfiledescriptor);
  }
}