Skip to content

Commit 6fb7fd3

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #7267494, issue #7212347" into jb-mr1-dev
2 parents 33c3689 + c428aae commit 6fb7fd3

File tree

8 files changed

+149
-79
lines changed

8 files changed

+149
-79
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4530,6 +4530,14 @@ public final IContentProvider acquireExistingProvider(
45304530

45314531
IContentProvider provider = pr.mProvider;
45324532
IBinder jBinder = provider.asBinder();
4533+
if (!jBinder.isBinderAlive()) {
4534+
// The hosting process of the provider has died; we can't
4535+
// use this one.
4536+
Log.i(TAG, "Acquiring provider " + auth + " for user " + userId
4537+
+ ": existing object's process dead");
4538+
handleUnstableProviderDiedLocked(jBinder, true);
4539+
return null;
4540+
}
45334541

45344542
// Only increment the ref count if we have one. If we don't then the
45354543
// provider is not reference counted and never needs to be released.
@@ -4670,33 +4678,37 @@ final void completeRemoveProvider(ProviderRefCount prc) {
46704678
}
46714679

46724680
final void handleUnstableProviderDied(IBinder provider, boolean fromClient) {
4673-
synchronized(mProviderMap) {
4674-
ProviderRefCount prc = mProviderRefCountMap.get(provider);
4675-
if (prc != null) {
4676-
if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider "
4677-
+ provider + " " + prc.holder.info.name);
4678-
mProviderRefCountMap.remove(provider);
4679-
if (prc.client != null && prc.client.mNames != null) {
4680-
for (String name : prc.client.mNames) {
4681-
ProviderClientRecord pr = mProviderMap.get(name);
4682-
if (pr != null && pr.mProvider.asBinder() == provider) {
4683-
Slog.i(TAG, "Removing dead content provider: " + name);
4684-
mProviderMap.remove(name);
4685-
}
4681+
synchronized (mProviderMap) {
4682+
handleUnstableProviderDiedLocked(provider, fromClient);
4683+
}
4684+
}
4685+
4686+
final void handleUnstableProviderDiedLocked(IBinder provider, boolean fromClient) {
4687+
ProviderRefCount prc = mProviderRefCountMap.get(provider);
4688+
if (prc != null) {
4689+
if (DEBUG_PROVIDER) Slog.v(TAG, "Cleaning up dead provider "
4690+
+ provider + " " + prc.holder.info.name);
4691+
mProviderRefCountMap.remove(provider);
4692+
if (prc.client != null && prc.client.mNames != null) {
4693+
for (String name : prc.client.mNames) {
4694+
ProviderClientRecord pr = mProviderMap.get(name);
4695+
if (pr != null && pr.mProvider.asBinder() == provider) {
4696+
Slog.i(TAG, "Removing dead content provider: " + name);
4697+
mProviderMap.remove(name);
46864698
}
46874699
}
4688-
if (fromClient) {
4689-
// We found out about this due to execution in our client
4690-
// code. Tell the activity manager about it now, to ensure
4691-
// that the next time we go to do anything with the provider
4692-
// it knows it is dead (so we don't race with its death
4693-
// notification).
4694-
try {
4695-
ActivityManagerNative.getDefault().unstableProviderDied(
4696-
prc.holder.connection);
4697-
} catch (RemoteException e) {
4698-
//do nothing content provider object is dead any way
4699-
}
4700+
}
4701+
if (fromClient) {
4702+
// We found out about this due to execution in our client
4703+
// code. Tell the activity manager about it now, to ensure
4704+
// that the next time we go to do anything with the provider
4705+
// it knows it is dead (so we don't race with its death
4706+
// notification).
4707+
try {
4708+
ActivityManagerNative.getDefault().unstableProviderDied(
4709+
prc.holder.connection);
4710+
} catch (RemoteException e) {
4711+
//do nothing content provider object is dead any way
47004712
}
47014713
}
47024714
}

core/java/android/os/IPowerManager.aidl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ interface IPowerManager
3737
void nap(long time);
3838

3939
boolean isScreenOn();
40-
void reboot(String reason);
40+
void reboot(boolean confirm, String reason, boolean wait);
41+
void shutdown(boolean confirm, boolean wait);
4142
void crash(String message);
4243

4344
void setStayOnSetting(int val);

core/java/android/os/PowerManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ public boolean isScreenOn() {
596596
*/
597597
public void reboot(String reason) {
598598
try {
599-
mService.reboot(reason);
599+
mService.reboot(false, reason, true);
600600
} catch (RemoteException e) {
601601
}
602602
}

services/java/com/android/server/BatteryService.java

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public final class BatteryService extends Binder {
127127
private long mDischargeStartTime;
128128
private int mDischargeStartLevel;
129129

130+
private boolean mUpdatesStopped;
131+
130132
private Led mLed;
131133

132134
private boolean mSentLowBatteryBroadcast = false;
@@ -231,7 +233,7 @@ private void shutdownIfNoPowerLocked() {
231233
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
232234
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
233235
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
234-
mContext.startActivity(intent);
236+
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
235237
}
236238
}
237239

@@ -244,16 +246,18 @@ private void shutdownIfOverTempLocked() {
244246
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
245247
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
246248
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
247-
mContext.startActivity(intent);
249+
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
248250
}
249251
}
250252

251253
private void updateLocked() {
252-
// Update the values of mAcOnline, et. all.
253-
native_update();
254+
if (!mUpdatesStopped) {
255+
// Update the values of mAcOnline, et. all.
256+
native_update();
254257

255-
// Process the new values.
256-
processValuesLocked();
258+
// Process the new values.
259+
processValuesLocked();
260+
}
257261
}
258262

259263
private void processValuesLocked() {
@@ -543,6 +547,9 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
543547
synchronized (mLock) {
544548
if (args == null || args.length == 0 || "-a".equals(args[0])) {
545549
pw.println("Current Battery Service state:");
550+
if (mUpdatesStopped) {
551+
pw.println(" (UPDATES STOPPED -- use 'reset' to restart)");
552+
}
546553
pw.println(" AC powered: " + mAcOnline);
547554
pw.println(" USB powered: " + mUsbOnline);
548555
pw.println(" Wireless powered: " + mWirelessOnline);
@@ -554,35 +561,41 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
554561
pw.println(" voltage:" + mBatteryVoltage);
555562
pw.println(" temperature: " + mBatteryTemperature);
556563
pw.println(" technology: " + mBatteryTechnology);
557-
} else if (false) {
558-
// DO NOT SUBMIT WITH THIS TURNED ON
559-
if (args.length == 3 && "set".equals(args[0])) {
560-
String key = args[1];
561-
String value = args[2];
562-
try {
563-
boolean update = true;
564-
if ("ac".equals(key)) {
565-
mAcOnline = Integer.parseInt(value) != 0;
566-
} else if ("usb".equals(key)) {
567-
mUsbOnline = Integer.parseInt(value) != 0;
568-
} else if ("wireless".equals(key)) {
569-
mWirelessOnline = Integer.parseInt(value) != 0;
570-
} else if ("status".equals(key)) {
571-
mBatteryStatus = Integer.parseInt(value);
572-
} else if ("level".equals(key)) {
573-
mBatteryLevel = Integer.parseInt(value);
574-
} else if ("invalid".equals(key)) {
575-
mInvalidCharger = Integer.parseInt(value);
576-
} else {
577-
update = false;
578-
}
579-
if (update) {
580-
processValuesLocked();
581-
}
582-
} catch (NumberFormatException ex) {
583-
pw.println("Bad value: " + value);
564+
} else if (args.length == 3 && "set".equals(args[0])) {
565+
String key = args[1];
566+
String value = args[2];
567+
try {
568+
boolean update = true;
569+
if ("ac".equals(key)) {
570+
mAcOnline = Integer.parseInt(value) != 0;
571+
} else if ("usb".equals(key)) {
572+
mUsbOnline = Integer.parseInt(value) != 0;
573+
} else if ("wireless".equals(key)) {
574+
mWirelessOnline = Integer.parseInt(value) != 0;
575+
} else if ("status".equals(key)) {
576+
mBatteryStatus = Integer.parseInt(value);
577+
} else if ("level".equals(key)) {
578+
mBatteryLevel = Integer.parseInt(value);
579+
} else if ("invalid".equals(key)) {
580+
mInvalidCharger = Integer.parseInt(value);
581+
} else {
582+
pw.println("Unknown set option: " + key);
583+
update = false;
584584
}
585+
if (update) {
586+
mUpdatesStopped = true;
587+
processValuesLocked();
588+
}
589+
} catch (NumberFormatException ex) {
590+
pw.println("Bad value: " + value);
585591
}
592+
} else if (args.length == 1 && "reset".equals(args[0])) {
593+
mUpdatesStopped = false;
594+
updateLocked();
595+
} else {
596+
pw.println("Dump current battery state, or:");
597+
pw.println(" set ac|usb|wireless|status|level|invalid <value>");
598+
pw.println(" reset");
586599
}
587600
}
588601
}

services/java/com/android/server/ShutdownActivity.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
package com.android.server;
1818

1919
import android.app.Activity;
20+
import android.content.Context;
2021
import android.content.Intent;
2122
import android.os.Bundle;
2223
import android.os.Handler;
24+
import android.os.IPowerManager;
25+
import android.os.RemoteException;
26+
import android.os.ServiceManager;
2327
import android.util.Slog;
2428

2529
import com.android.server.power.ShutdownThread;
@@ -39,15 +43,27 @@ protected void onCreate(Bundle savedInstanceState) {
3943
mConfirm = intent.getBooleanExtra(Intent.EXTRA_KEY_CONFIRM, false);
4044
Slog.i(TAG, "onCreate(): confirm=" + mConfirm);
4145

42-
Handler h = new Handler();
43-
h.post(new Runnable() {
46+
Thread thr = new Thread("ShutdownActivity") {
47+
@Override
4448
public void run() {
45-
if (mReboot) {
46-
ShutdownThread.reboot(ShutdownActivity.this, null, mConfirm);
47-
} else {
48-
ShutdownThread.shutdown(ShutdownActivity.this, mConfirm);
49+
IPowerManager pm = IPowerManager.Stub.asInterface(
50+
ServiceManager.getService(Context.POWER_SERVICE));
51+
try {
52+
if (mReboot) {
53+
pm.reboot(mConfirm, null, false);
54+
} else {
55+
pm.shutdown(mConfirm, false);
56+
}
57+
} catch (RemoteException e) {
4958
}
5059
}
51-
});
60+
};
61+
thr.start();
62+
finish();
63+
// Wait for us to tell the power manager to shutdown.
64+
try {
65+
thr.join();
66+
} catch (InterruptedException e) {
67+
}
5268
}
5369
}

services/java/com/android/server/Watchdog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void checkReboot(boolean fromAlarm) {
305305
void rebootSystem(String reason) {
306306
Slog.i(TAG, "Rebooting system because: " + reason);
307307
PowerManagerService pms = (PowerManagerService) ServiceManager.getService("power");
308-
pms.reboot(reason);
308+
pms.reboot(false, reason, false);
309309
}
310310

311311
/**

services/java/com/android/server/power/PowerManagerService.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,30 +1602,51 @@ private void handleBootCompletedLocked() {
16021602
}
16031603

16041604
/**
1605-
* Reboot the device immediately, passing 'reason' (may be null)
1605+
* Reboot the device, passing 'reason' (may be null)
16061606
* to the underlying __reboot system call. Should not return.
16071607
*/
16081608
@Override // Binder call
1609-
public void reboot(String reason) {
1609+
public void reboot(boolean confirm, String reason, boolean wait) {
16101610
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
16111611

16121612
final long ident = Binder.clearCallingIdentity();
16131613
try {
1614-
rebootInternal(reason);
1614+
rebootInternal(false, confirm, reason, wait);
16151615
} finally {
16161616
Binder.restoreCallingIdentity(ident);
16171617
}
16181618
}
16191619

1620-
private void rebootInternal(final String reason) {
1620+
/**
1621+
* Shutdown the devic, passing 'reason' (may be null)
1622+
* to the underlying __reboot system call. Should not return.
1623+
*/
1624+
@Override // Binder call
1625+
public void shutdown(boolean confirm, boolean wait) {
1626+
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
1627+
1628+
final long ident = Binder.clearCallingIdentity();
1629+
try {
1630+
rebootInternal(true, confirm, null, wait);
1631+
} finally {
1632+
Binder.restoreCallingIdentity(ident);
1633+
}
1634+
}
1635+
1636+
private void rebootInternal(final boolean shutdown, final boolean confirm,
1637+
final String reason, boolean wait) {
16211638
if (mHandler == null || !mSystemReady) {
16221639
throw new IllegalStateException("Too early to call reboot()");
16231640
}
16241641

16251642
Runnable runnable = new Runnable() {
16261643
public void run() {
16271644
synchronized (this) {
1628-
ShutdownThread.reboot(mContext, reason, false);
1645+
if (shutdown) {
1646+
ShutdownThread.shutdown(mContext, confirm);
1647+
} else {
1648+
ShutdownThread.reboot(mContext, reason, confirm);
1649+
}
16291650
}
16301651
}
16311652
};
@@ -1636,11 +1657,13 @@ public void run() {
16361657
mHandler.sendMessage(msg);
16371658

16381659
// PowerManager.reboot() is documented not to return so just wait for the inevitable.
1639-
synchronized (runnable) {
1640-
while (true) {
1641-
try {
1642-
runnable.wait();
1643-
} catch (InterruptedException e) {
1660+
if (wait) {
1661+
synchronized (runnable) {
1662+
while (true) {
1663+
try {
1664+
runnable.wait();
1665+
} catch (InterruptedException e) {
1666+
}
16441667
}
16451668
}
16461669
}

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgePowerManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ public void nap(long arg0) throws RemoteException {
6060
}
6161

6262
@Override
63-
public void reboot(String arg0) throws RemoteException {
63+
public void reboot(boolean confirm, String reason, boolean wait) {
64+
// pass for now.
65+
}
66+
67+
@Override
68+
public void shutdown(boolean confirm, boolean wait) {
6469
// pass for now.
6570
}
6671

0 commit comments

Comments
 (0)