Fixes to DevicePolicyManager.setPasswordExpirationTimeout
* Fix permissions problem in DevicePolicyManager
* Allow short timeouts (primarily for testing)
* Remove unused debugging code
Bug: 3212583
Change-Id: I3770b1c6f090363e8e8d65db92839cd53de05c45
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index a18fdac..f169cd7 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -691,8 +691,6 @@
*
* <p>To disable password expiration, a value of 0 may be used for timeout.
*
- * <p>Timeout must be at least 1 day or IllegalArgumentException will be thrown.
- *
* <p>The calling device admin must have requested
* {@link DeviceAdminInfo#USES_POLICY_EXPIRE_PASSWORD} to be able to call this
* method; if it has not, a security exception will be thrown.
diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java
index 2b43b013..53a19f5 100644
--- a/services/java/com/android/server/DevicePolicyManagerService.java
+++ b/services/java/com/android/server/DevicePolicyManagerService.java
@@ -41,9 +41,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.net.ConnectivityManager;
+import android.content.pm.ResolveInfo;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -55,9 +54,9 @@
import android.os.ServiceManager;
import android.os.SystemClock;
import android.provider.Settings;
-import android.util.Slog;
import android.util.PrintWriterPrinter;
import android.util.Printer;
+import android.util.Slog;
import android.util.Xml;
import android.view.WindowManagerPolicy;
@@ -89,9 +88,6 @@
= "com.android.server.ACTION_EXPIRED_PASSWORD_NOTIFICATION";
private static final long MS_PER_DAY = 86400 * 1000;
- private static final long MS_PER_HOUR = 3600 * 1000;
- private static final long MS_PER_MINUTE = 60 * 1000;
- private static final long MIN_TIMEOUT = 86400 * 1000; // minimum expiration timeout is 1 day
final Context mContext;
final MyPackageMonitor mMonitor;
@@ -364,6 +360,7 @@
}
class MyPackageMonitor extends PackageMonitor {
+ @Override
public void onSomePackagesChanged() {
synchronized (DevicePolicyManagerService.this) {
boolean removed = false;
@@ -410,13 +407,6 @@
context.registerReceiver(mReceiver, filter);
}
- static String countdownString(long time) {
- long days = time / MS_PER_DAY;
- long hours = (time / MS_PER_HOUR) % 24;
- long minutes = (time / MS_PER_MINUTE) % 60;
- return days + "d" + hours + "h" + minutes + "m";
- }
-
protected void setExpirationAlarmCheckLocked(Context context) {
final long expiration = getPasswordExpirationLocked(null);
final long now = System.currentTimeMillis();
@@ -430,12 +420,17 @@
alarmTime = now + MS_PER_DAY;
}
- AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- PendingIntent pi = PendingIntent.getBroadcast(context, REQUEST_EXPIRE_PASSWORD,
- new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION),
- PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
- am.cancel(pi);
- am.set(AlarmManager.RTC, alarmTime, pi);
+ long token = Binder.clearCallingIdentity();
+ try {
+ AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ PendingIntent pi = PendingIntent.getBroadcast(context, REQUEST_EXPIRE_PASSWORD,
+ new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION),
+ PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
+ am.cancel(pi);
+ am.set(AlarmManager.RTC, alarmTime, pi);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
private IPowerManager getIPowerManager() {
@@ -993,8 +988,8 @@
if (who == null) {
throw new NullPointerException("ComponentName is null");
}
- if (timeout != 0L && timeout < MIN_TIMEOUT) {
- throw new IllegalArgumentException("Timeout must be > " + MIN_TIMEOUT + "ms");
+ if (timeout < 0) {
+ throw new IllegalArgumentException("Timeout must be >= 0 ms");
}
ActiveAdmin ap = getActiveAdminForCallerLocked(who,
DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD);