Merge "Fix issue #7267494, issue #7212347" into jb-mr1-dev

This commit is contained in:
Dianne Hackborn
2012-10-03 18:45:37 -07:00
committed by Android (Google) Code Review
8 changed files with 149 additions and 79 deletions

View File

@ -4530,6 +4530,14 @@ public final class ActivityThread {
IContentProvider provider = pr.mProvider; IContentProvider provider = pr.mProvider;
IBinder jBinder = provider.asBinder(); IBinder jBinder = provider.asBinder();
if (!jBinder.isBinderAlive()) {
// The hosting process of the provider has died; we can't
// use this one.
Log.i(TAG, "Acquiring provider " + auth + " for user " + userId
+ ": existing object's process dead");
handleUnstableProviderDiedLocked(jBinder, true);
return null;
}
// Only increment the ref count if we have one. If we don't then the // Only increment the ref count if we have one. If we don't then the
// provider is not reference counted and never needs to be released. // provider is not reference counted and never needs to be released.
@ -4670,7 +4678,12 @@ public final class ActivityThread {
} }
final void handleUnstableProviderDied(IBinder provider, boolean fromClient) { final void handleUnstableProviderDied(IBinder provider, boolean fromClient) {
synchronized(mProviderMap) { synchronized (mProviderMap) {
handleUnstableProviderDiedLocked(provider, fromClient);
}
}
final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) {
ProviderRefCount prc = mProviderRefCountMap.get(provider); ProviderRefCount prc = mProviderRefCountMap.get(provider);
if (prc != null) { if (prc != null) {
if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider " if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider "
@ -4700,7 +4713,6 @@ public final class ActivityThread {
} }
} }
} }
}
private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider, private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider,
ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) { ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) {

View File

@ -37,7 +37,8 @@ interface IPowerManager
void nap(long time); void nap(long time);
boolean isScreenOn(); boolean isScreenOn();
void reboot(String reason); void reboot(boolean confirm, String reason, boolean wait);
void shutdown(boolean confirm, boolean wait);
void crash(String message); void crash(String message);
void setStayOnSetting(int val); void setStayOnSetting(int val);

View File

@ -596,7 +596,7 @@ public final class PowerManager {
*/ */
public void reboot(String reason) { public void reboot(String reason) {
try { try {
mService.reboot(reason); mService.reboot(false, reason, true);
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }

View File

@ -127,6 +127,8 @@ public final class BatteryService extends Binder {
private long mDischargeStartTime; private long mDischargeStartTime;
private int mDischargeStartLevel; private int mDischargeStartLevel;
private boolean mUpdatesStopped;
private Led mLed; private Led mLed;
private boolean mSentLowBatteryBroadcast = false; private boolean mSentLowBatteryBroadcast = false;
@ -231,7 +233,7 @@ public final class BatteryService extends Binder {
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false); intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent); mContext.startActivityAsUser(intent, UserHandle.CURRENT);
} }
} }
@ -244,17 +246,19 @@ public final class BatteryService extends Binder {
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false); intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent); mContext.startActivityAsUser(intent, UserHandle.CURRENT);
} }
} }
private void updateLocked() { private void updateLocked() {
if (!mUpdatesStopped) {
// Update the values of mAcOnline, et. all. // Update the values of mAcOnline, et. all.
native_update(); native_update();
// Process the new values. // Process the new values.
processValuesLocked(); processValuesLocked();
} }
}
private void processValuesLocked() { private void processValuesLocked() {
boolean logOutlier = false; boolean logOutlier = false;
@ -543,6 +547,9 @@ public final class BatteryService extends Binder {
synchronized (mLock) { synchronized (mLock) {
if (args == null || args.length == 0 || "-a".equals(args[0])) { if (args == null || args.length == 0 || "-a".equals(args[0])) {
pw.println("Current Battery Service state:"); pw.println("Current Battery Service state:");
if (mUpdatesStopped) {
pw.println(" (UPDATES STOPPED -- use 'reset' to restart)");
}
pw.println(" AC powered: " + mAcOnline); pw.println(" AC powered: " + mAcOnline);
pw.println(" USB powered: " + mUsbOnline); pw.println(" USB powered: " + mUsbOnline);
pw.println(" Wireless powered: " + mWirelessOnline); pw.println(" Wireless powered: " + mWirelessOnline);
@ -554,9 +561,7 @@ public final class BatteryService extends Binder {
pw.println(" voltage:" + mBatteryVoltage); pw.println(" voltage:" + mBatteryVoltage);
pw.println(" temperature: " + mBatteryTemperature); pw.println(" temperature: " + mBatteryTemperature);
pw.println(" technology: " + mBatteryTechnology); pw.println(" technology: " + mBatteryTechnology);
} else if (false) { } else if (args.length == 3 && "set".equals(args[0])) {
// DO NOT SUBMIT WITH THIS TURNED ON
if (args.length == 3 && "set".equals(args[0])) {
String key = args[1]; String key = args[1];
String value = args[2]; String value = args[2];
try { try {
@ -574,15 +579,23 @@ public final class BatteryService extends Binder {
} else if ("invalid".equals(key)) { } else if ("invalid".equals(key)) {
mInvalidCharger = Integer.parseInt(value); mInvalidCharger = Integer.parseInt(value);
} else { } else {
pw.println("Unknown set option: " + key);
update = false; update = false;
} }
if (update) { if (update) {
mUpdatesStopped = true;
processValuesLocked(); processValuesLocked();
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
pw.println("Bad value: " + value); pw.println("Bad value: " + value);
} }
} } else if (args.length == 1 && "reset".equals(args[0])) {
mUpdatesStopped = false;
updateLocked();
} else {
pw.println("Dump current battery state, or:");
pw.println(" set ac|usb|wireless|status|level|invalid <value>");
pw.println(" reset");
} }
} }
} }

View File

@ -17,9 +17,13 @@
package com.android.server; package com.android.server;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog; import android.util.Slog;
import com.android.server.power.ShutdownThread; import com.android.server.power.ShutdownThread;
@ -39,15 +43,27 @@ public class ShutdownActivity extends Activity {
mConfirm = intent.getBooleanExtra(Intent.EXTRA_KEY_CONFIRM, false); mConfirm = intent.getBooleanExtra(Intent.EXTRA_KEY_CONFIRM, false);
Slog.i(TAG, "onCreate(): confirm=" + mConfirm); Slog.i(TAG, "onCreate(): confirm=" + mConfirm);
Handler h = new Handler(); Thread thr = new Thread("ShutdownActivity") {
h.post(new Runnable() { @Override
public void run() { public void run() {
IPowerManager pm = IPowerManager.Stub.asInterface(
ServiceManager.getService(Context.POWER_SERVICE));
try {
if (mReboot) { if (mReboot) {
ShutdownThread.reboot(ShutdownActivity.this, null, mConfirm); pm.reboot(mConfirm, null, false);
} else { } else {
ShutdownThread.shutdown(ShutdownActivity.this, mConfirm); pm.shutdown(mConfirm, false);
}
} catch (RemoteException e) {
} }
} }
}); };
thr.start();
finish();
// Wait for us to tell the power manager to shutdown.
try {
thr.join();
} catch (InterruptedException e) {
}
} }
} }

View File

@ -305,7 +305,7 @@ public class Watchdog extends Thread {
void rebootSystem(String reason) { void rebootSystem(String reason) {
Slog.i(TAG, "Rebooting system because: " + reason); Slog.i(TAG, "Rebooting system because: " + reason);
PowerManagerService pms = (PowerManagerService) ServiceManager.getService("power"); PowerManagerService pms = (PowerManagerService) ServiceManager.getService("power");
pms.reboot(reason); pms.reboot(false, reason, false);
} }
/** /**

View File

@ -1602,22 +1602,39 @@ public final class PowerManagerService extends IPowerManager.Stub
} }
/** /**
* Reboot the device immediately, passing 'reason' (may be null) * Reboot the device, passing 'reason' (may be null)
* to the underlying __reboot system call. Should not return. * to the underlying __reboot system call. Should not return.
*/ */
@Override // Binder call @Override // Binder call
public void reboot(String reason) { public void reboot(boolean confirm, String reason, boolean wait) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity();
try { try {
rebootInternal(reason); rebootInternal(false, confirm, reason, wait);
} finally { } finally {
Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident);
} }
} }
private void rebootInternal(final String reason) { /**
* Shutdown the devic, passing 'reason' (may be null)
* to the underlying __reboot system call. Should not return.
*/
@Override // Binder call
public void shutdown(boolean confirm, boolean wait) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
final long ident = Binder.clearCallingIdentity();
try {
rebootInternal(true, confirm, null, wait);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
private void rebootInternal(final boolean shutdown, final boolean confirm,
final String reason, boolean wait) {
if (mHandler == null || !mSystemReady) { if (mHandler == null || !mSystemReady) {
throw new IllegalStateException("Too early to call reboot()"); throw new IllegalStateException("Too early to call reboot()");
} }
@ -1625,7 +1642,11 @@ public final class PowerManagerService extends IPowerManager.Stub
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
public void run() { public void run() {
synchronized (this) { synchronized (this) {
ShutdownThread.reboot(mContext, reason, false); if (shutdown) {
ShutdownThread.shutdown(mContext, confirm);
} else {
ShutdownThread.reboot(mContext, reason, confirm);
}
} }
} }
}; };
@ -1636,6 +1657,7 @@ public final class PowerManagerService extends IPowerManager.Stub
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
// PowerManager.reboot() is documented not to return so just wait for the inevitable. // PowerManager.reboot() is documented not to return so just wait for the inevitable.
if (wait) {
synchronized (runnable) { synchronized (runnable) {
while (true) { while (true) {
try { try {
@ -1645,6 +1667,7 @@ public final class PowerManagerService extends IPowerManager.Stub
} }
} }
} }
}
/** /**
* Crash the runtime (causing a complete restart of the Android framework). * Crash the runtime (causing a complete restart of the Android framework).

View File

@ -60,7 +60,12 @@ public class BridgePowerManager implements IPowerManager {
} }
@Override @Override
public void reboot(String arg0) throws RemoteException { public void reboot(boolean confirm, String reason, boolean wait) {
// pass for now.
}
@Override
public void shutdown(boolean confirm, boolean wait) {
// pass for now. // pass for now.
} }