Skip to content

Commit a53de06

Browse files
author
Dianne Hackborn
committed
Add callback hack to find out when to load system properties.
Use this to reload the trace and layout bounds properties. This is ONLY for debugging. Change-Id: I1c4bdb52c823520c352c5bac45fa9ee31160793c
1 parent 8b2e37e commit a53de06

File tree

10 files changed

+180
-10
lines changed

10 files changed

+180
-10
lines changed

core/java/android/os/IBinder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public interface IBinder {
140140
*/
141141
int LIKE_TRANSACTION = ('_'<<24)|('L'<<16)|('I'<<8)|'K';
142142

143+
/** @hide */
144+
int SYSPROPS_TRANSACTION = ('_'<<24)|('S'<<16)|('P'<<8)|'R';
145+
143146
/**
144147
* Flag to {@link #transact}: this is a one-way call, meaning that the
145148
* caller returns immediately, without waiting for a result from the

core/java/android/os/ServiceManagerNative.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package android.os;
1818

19+
import java.util.ArrayList;
20+
1921

2022
/**
2123
* Native implementation of the service manager. Most clients will only
@@ -151,14 +153,32 @@ public void addService(String name, IBinder service, boolean allowIsolated)
151153
}
152154

153155
public String[] listServices() throws RemoteException {
154-
Parcel data = Parcel.obtain();
155-
Parcel reply = Parcel.obtain();
156-
data.writeInterfaceToken(IServiceManager.descriptor);
157-
mRemote.transact(LIST_SERVICES_TRANSACTION, data, reply, 0);
158-
String[] list = reply.readStringArray();
159-
reply.recycle();
160-
data.recycle();
161-
return list;
156+
ArrayList<String> services = new ArrayList<String>();
157+
int n = 0;
158+
while (true) {
159+
Parcel data = Parcel.obtain();
160+
Parcel reply = Parcel.obtain();
161+
data.writeInterfaceToken(IServiceManager.descriptor);
162+
data.writeInt(n);
163+
n++;
164+
try {
165+
boolean res = mRemote.transact(LIST_SERVICES_TRANSACTION, data, reply, 0);
166+
if (!res) {
167+
break;
168+
}
169+
} catch (RuntimeException e) {
170+
// The result code that is returned by the C++ code can
171+
// cause the call to throw an exception back instead of
172+
// returning a nice result... so eat it here and go on.
173+
break;
174+
}
175+
services.add(reply.readString());
176+
reply.recycle();
177+
data.recycle();
178+
}
179+
String[] array = new String[services.size()];
180+
services.toArray(array);
181+
return array;
162182
}
163183

164184
public void setPermissionController(IPermissionController controller)

core/java/android/os/SystemProperties.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package android.os;
1818

19+
import java.util.ArrayList;
20+
21+
import android.util.Log;
22+
1923

2024
/**
2125
* Gives access to the system properties store. The system properties
@@ -28,12 +32,15 @@ public class SystemProperties
2832
public static final int PROP_NAME_MAX = 31;
2933
public static final int PROP_VALUE_MAX = 91;
3034

35+
private static final ArrayList<Runnable> sChangeCallbacks = new ArrayList<Runnable>();
36+
3137
private static native String native_get(String key);
3238
private static native String native_get(String key, String def);
3339
private static native int native_get_int(String key, int def);
3440
private static native long native_get_long(String key, long def);
3541
private static native boolean native_get_boolean(String key, boolean def);
3642
private static native void native_set(String key, String def);
43+
private static native void native_add_change_callback();
3744

3845
/**
3946
* Get the value for the given key.
@@ -124,4 +131,26 @@ public static void set(String key, String val) {
124131
}
125132
native_set(key, val);
126133
}
134+
135+
public static void addChangeCallback(Runnable callback) {
136+
synchronized (sChangeCallbacks) {
137+
if (sChangeCallbacks.size() == 0) {
138+
native_add_change_callback();
139+
}
140+
sChangeCallbacks.add(callback);
141+
}
142+
}
143+
144+
static void callChangeCallbacks() {
145+
synchronized (sChangeCallbacks) {
146+
//Log.i("foo", "Calling " + sChangeCallbacks.size() + " change callbacks!");
147+
if (sChangeCallbacks.size() == 0) {
148+
return;
149+
}
150+
ArrayList<Runnable> callbacks = new ArrayList<Runnable>(sChangeCallbacks);
151+
for (int i=0; i<callbacks.size(); i++) {
152+
callbacks.get(i).run();
153+
}
154+
}
155+
}
127156
}

core/java/android/os/Trace.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ public final class Trace {
4747

4848
public static final String PROPERTY_TRACE_TAG_ENABLEFLAGS = "debug.atrace.tags.enableflags";
4949

50-
private static final long sEnabledTags = nativeGetEnabledTags();
50+
private static long sEnabledTags = nativeGetEnabledTags();
5151

5252
private static native long nativeGetEnabledTags();
5353
private static native void nativeTraceCounter(long tag, String name, int value);
5454
private static native void nativeTraceBegin(long tag, String name);
5555
private static native void nativeTraceEnd(long tag);
5656

57+
static {
58+
SystemProperties.addChangeCallback(new Runnable() {
59+
@Override public void run() {
60+
sEnabledTags = nativeGetEnabledTags();
61+
}
62+
});
63+
}
64+
5765
private Trace() {
5866
}
5967

core/java/android/view/View.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17250,7 +17250,7 @@ public void setPooled(boolean isPooled) {
1725017250
/**
1725117251
* Show where the margins, bounds and layout bounds are for each view.
1725217252
*/
17253-
final boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false);
17253+
boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false);
1725417254

1725517255
/**
1725617256
* Point used to compute visible regions.

core/java/android/view/ViewRootImpl.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ public ViewRootImpl(Context context) {
408408

409409
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
410410
mAttachInfo.mScreenOn = powerManager.isScreenOn();
411+
loadSystemProperties();
411412
}
412413

413414
/**
@@ -846,6 +847,16 @@ void invalidate() {
846847
scheduleTraversals();
847848
}
848849

850+
void invalidateWorld(View view) {
851+
view.invalidate();
852+
if (view instanceof ViewGroup) {
853+
ViewGroup parent = (ViewGroup)view;
854+
for (int i=0; i<parent.getChildCount(); i++) {
855+
invalidateWorld(parent.getChildAt(i));
856+
}
857+
}
858+
}
859+
849860
public void invalidateChild(View child, Rect dirty) {
850861
invalidateChildInParent(null, dirty);
851862
}
@@ -2730,6 +2741,7 @@ private static void forceLayout(View view) {
27302741
private final static int MSG_INVALIDATE_DISPLAY_LIST = 21;
27312742
private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 22;
27322743
private final static int MSG_DISPATCH_DONE_ANIMATING = 23;
2744+
private final static int MSG_INVALIDATE_WORLD = 24;
27332745

27342746
final class ViewRootHandler extends Handler {
27352747
@Override
@@ -2997,6 +3009,9 @@ public void handleMessage(Message msg) {
29973009
case MSG_DISPATCH_DONE_ANIMATING: {
29983010
handleDispatchDoneAnimating();
29993011
} break;
3012+
case MSG_INVALIDATE_WORLD: {
3013+
invalidateWorld(mView);
3014+
} break;
30003015
}
30013016
}
30023017
}
@@ -4016,6 +4031,17 @@ public void requestUpdateConfiguration(Configuration config) {
40164031
mHandler.sendMessage(msg);
40174032
}
40184033

4034+
public void loadSystemProperties() {
4035+
boolean layout = SystemProperties.getBoolean(
4036+
View.DEBUG_LAYOUT_PROPERTY, false);
4037+
if (layout != mAttachInfo.mDebugLayout) {
4038+
mAttachInfo.mDebugLayout = layout;
4039+
if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) {
4040+
mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200);
4041+
}
4042+
}
4043+
}
4044+
40194045
private void destroyHardwareRenderer() {
40204046
AttachInfo attachInfo = mAttachInfo;
40214047
HardwareRenderer hardwareRenderer = attachInfo.mHardwareRenderer;

core/java/android/view/WindowManagerImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.PixelFormat;
2424
import android.opengl.ManagedEGLContext;
2525
import android.os.IBinder;
26+
import android.os.SystemProperties;
2627
import android.util.AndroidRuntimeException;
2728
import android.util.Log;
2829
import android.view.inputmethod.InputMethodManager;
@@ -112,6 +113,8 @@ public class WindowManagerImpl implements WindowManager {
112113
private WindowManager.LayoutParams[] mParams;
113114
private boolean mNeedsEglTerminate;
114115

116+
private Runnable mSystemPropertyUpdater = null;
117+
115118
private final static Object sLock = new Object();
116119
private final static WindowManagerImpl sWindowManager = new WindowManagerImpl();
117120
private final static HashMap<CompatibilityInfo, WindowManager> sCompatWindowManagers
@@ -237,6 +240,22 @@ private void addView(View view, ViewGroup.LayoutParams params,
237240
View panelParentView = null;
238241

239242
synchronized (this) {
243+
// Start watching for system property changes.
244+
if (mSystemPropertyUpdater == null) {
245+
mSystemPropertyUpdater = new Runnable() {
246+
@Override public void run() {
247+
synchronized (this) {
248+
synchronized (this) {
249+
for (ViewRootImpl root : mRoots) {
250+
root.loadSystemProperties();
251+
}
252+
}
253+
}
254+
}
255+
};
256+
SystemProperties.addChangeCallback(mSystemPropertyUpdater);
257+
}
258+
240259
// Here's an odd/questionable case: if someone tries to add a
241260
// view multiple times, then we simply bump up a nesting count
242261
// and they need to remove the view the corresponding number of

core/jni/android_os_SystemProperties.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
** limitations under the License.
1616
*/
1717

18+
#define LOG_TAG "SysPropJNI"
19+
1820
#include "cutils/properties.h"
21+
#include "utils/misc.h"
22+
#include <utils/Log.h>
1923
#include "jni.h"
2024
#include "android_runtime/AndroidRuntime.h"
2125
#include <nativehelper/JNIHelp.h>
@@ -188,6 +192,34 @@ static void SystemProperties_set(JNIEnv *env, jobject clazz,
188192
}
189193
}
190194

195+
static JavaVM* sVM = NULL;
196+
static jclass sClazz = NULL;
197+
static jmethodID sCallChangeCallbacks;
198+
199+
static void do_report_sysprop_change() {
200+
//ALOGI("Java SystemProperties: VM=%p, Clazz=%p", sVM, sClazz);
201+
if (sVM != NULL && sClazz != NULL) {
202+
JNIEnv* env;
203+
if (sVM->GetEnv((void **)&env, JNI_VERSION_1_4) >= 0) {
204+
//ALOGI("Java SystemProperties: calling %p", sCallChangeCallbacks);
205+
env->CallStaticVoidMethod(sClazz, sCallChangeCallbacks);
206+
}
207+
}
208+
}
209+
210+
static void SystemProperties_add_change_callback(JNIEnv *env, jobject clazz)
211+
{
212+
// This is called with the Java lock held.
213+
if (sVM == NULL) {
214+
env->GetJavaVM(&sVM);
215+
}
216+
if (sClazz == NULL) {
217+
sClazz = (jclass) env->NewGlobalRef(clazz);
218+
sCallChangeCallbacks = env->GetStaticMethodID(sClazz, "callChangeCallbacks", "()V");
219+
add_sysprop_change_callback(do_report_sysprop_change, -10000);
220+
}
221+
}
222+
191223
static JNINativeMethod method_table[] = {
192224
{ "native_get", "(Ljava/lang/String;)Ljava/lang/String;",
193225
(void*) SystemProperties_getS },
@@ -201,6 +233,8 @@ static JNINativeMethod method_table[] = {
201233
(void*) SystemProperties_get_boolean },
202234
{ "native_set", "(Ljava/lang/String;Ljava/lang/String;)V",
203235
(void*) SystemProperties_set },
236+
{ "native_add_change_callback", "()V",
237+
(void*) SystemProperties_add_change_callback },
204238
};
205239

206240
int register_android_os_SystemProperties(JNIEnv *env)

core/jni/android_util_Binder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ class JavaBBinder : public BBinder
308308
env->DeleteLocalRef(excep2);
309309
}
310310

311+
// Need to always call through the native implementation of
312+
// SYSPROPS_TRANSACTION.
313+
if (code == SYSPROPS_TRANSACTION) {
314+
BBinder::onTransact(code, data, reply, flags);
315+
}
316+
311317
//aout << "onTransact to Java code; result=" << res << endl
312318
// << "Transact from " << this << " to Java code returning "
313319
// << reply << ": " << *reply << endl;

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,31 @@ public void run() {
15671567
@Override
15681568
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
15691569
throws RemoteException {
1570+
if (code == SYSPROPS_TRANSACTION) {
1571+
// We need to tell all apps about the system property change.
1572+
ArrayList<IBinder> procs = new ArrayList<IBinder>();
1573+
synchronized(this) {
1574+
for (SparseArray<ProcessRecord> apps : mProcessNames.getMap().values()) {
1575+
final int NA = apps.size();
1576+
for (int ia=0; ia<NA; ia++) {
1577+
ProcessRecord app = apps.valueAt(ia);
1578+
if (app.thread != null) {
1579+
procs.add(app.thread.asBinder());
1580+
}
1581+
}
1582+
}
1583+
}
1584+
1585+
int N = procs.size();
1586+
for (int i=0; i<N; i++) {
1587+
Parcel data2 = Parcel.obtain();
1588+
try {
1589+
procs.get(i).transact(IBinder.SYSPROPS_TRANSACTION, data2, null, 0);
1590+
} catch (RemoteException e) {
1591+
}
1592+
data2.recycle();
1593+
}
1594+
}
15701595
try {
15711596
return super.onTransact(code, data, reply, flags);
15721597
} catch (RuntimeException e) {

0 commit comments

Comments
 (0)