forked from AOSP-10/frameworks_base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mechanism to improve consistancy of notification
Supports two states: add and remove added death recipient for hal handle CRs-Fixed: 2539384,2538995 Change-Id: I50c94d8936d8cd07f7670eed4466aac65a6063c8
- Loading branch information
Mulugeta Engdaw
committed
Oct 15, 2019
1 parent
ef95607
commit 98cbe72
Showing
6 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
services/core/java/com/android/server/ActivityTriggerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) 2019, The Linux Foundation. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of The Linux Foundation nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.android.server; | ||
|
||
import android.content.pm.ApplicationInfo; | ||
import android.util.Slog; | ||
import android.content.Context; | ||
import com.android.server.am.HostingRecord; | ||
import java.lang.Runnable; | ||
import android.os.HandlerThread; | ||
import android.os.Handler; | ||
|
||
public class ActivityTriggerService extends SystemService { | ||
private static String TAG = "ActivityTriggerService"; | ||
public static final int PROC_ADDED_NOTIFICATION = 1; | ||
public static final int PROC_REMOVED_NOTIFICATION = 0; | ||
private EventHandlerThread eventHandler = new EventHandlerThread("EventHandlerThread"); | ||
|
||
public ActivityTriggerService(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
Slog.i(TAG, "Starting ActivityTriggerService"); | ||
eventHandler.start(); | ||
publishLocalService(ActivityTriggerService.class, this); | ||
} | ||
|
||
/*make non-blocking call to add a new event to the handler's queue. | ||
the event handler is the one responsible for running each event.*/ | ||
public void updateRecord(HostingRecord hr, ApplicationInfo info, int pid, int event) { | ||
if(hr != null) { | ||
eventHandler.getHandler().post(new LocalRunnable(info.packageName, info.longVersionCode, info.processName, pid, event)); | ||
} | ||
} | ||
|
||
public class EventHandlerThread extends HandlerThread { | ||
private Handler handler; | ||
public EventHandlerThread(String name) { | ||
super(name); //no priority specified | ||
} | ||
|
||
@Override | ||
protected void onLooperPrepared() { | ||
//attach a handler to the thread | ||
handler = new Handler(); | ||
} | ||
//get the handler that queues and runs Runnables | ||
public Handler getHandler() { | ||
return handler; | ||
} | ||
} | ||
|
||
static class LocalRunnable implements Runnable { | ||
private String packageName; | ||
private long lvCode; | ||
private String procName; | ||
private int pid; | ||
private int event; | ||
|
||
LocalRunnable(String packageName, long lvCode, String procName, int pid, int event) { | ||
this.packageName = packageName; | ||
this.lvCode = lvCode; | ||
this.procName = procName; | ||
this.pid = pid; | ||
this.event = event; | ||
} | ||
@Override | ||
public void run() { | ||
notifyAction_native(packageName, lvCode, procName, pid, event); | ||
} | ||
} | ||
|
||
//Native methods | ||
static native void notifyAction_native(String pkgName, long vCode, String procName, int pid, int event); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
services/core/jni/com_android_server_activityTriggerService.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2019, The Linux Foundation. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of The Linux Foundation nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "jni.h" | ||
#include <nativehelper/JNIHelp.h> | ||
#include "android_runtime/AndroidRuntime.h" | ||
#include <utils/Log.h> | ||
#include <dlfcn.h> | ||
#include <limits.h> | ||
|
||
namespace android { | ||
|
||
//structure which has a handle for dynamically loading the trigger handler lib. | ||
|
||
typedef struct dlLibHandler { | ||
void *handle; | ||
void (*set_info)(const char*, const char*, int *); | ||
const char *dlname; | ||
}dlLibhandler; | ||
|
||
//initialize the handler | ||
static dlLibHandler handler = { | ||
NULL, NULL, "libtrigger-handler.so" | ||
}; | ||
|
||
static void trigger_handler_lib_init() { | ||
bool dlError = false; | ||
handler.handle = dlopen(handler.dlname, RTLD_NOW | RTLD_LOCAL); | ||
/*no need to proceed if the lib isn't available*/ | ||
if(handler.handle == NULL) { | ||
ALOGE("Activity trigger handling disabled."); | ||
return; | ||
} | ||
*(void **) (&handler.set_info) = dlsym(handler.handle, "set_info"); | ||
if(handler.set_info == NULL) { | ||
dlError = true; | ||
} | ||
if(dlError) { | ||
handler.set_info = NULL; | ||
if(handler.handle) dlclose(handler.handle); | ||
handler.handle = NULL; | ||
} | ||
} | ||
|
||
static void notifyAction_native (JNIEnv* env, jobject /*jclazz*/,jstring pkgName, jlong vCode, jstring /*procName*/, jint pid_in, jint flag) { | ||
int pid = (int)pid_in; | ||
std::string versionCode = std::to_string((long)vCode) + std::to_string((int)flag); | ||
const char* version = versionCode.c_str(); | ||
|
||
if(pkgName && handler.set_info) { | ||
const char *package = env->GetStringUTFChars(pkgName, NULL); | ||
if(package) { | ||
(*handler.set_info)(package,version,&pid); | ||
env->ReleaseStringUTFChars(pkgName, package); | ||
} | ||
} | ||
} | ||
|
||
static JNINativeMethod method_list[] = { | ||
{ "notifyAction_native", "(Ljava/lang/String;JLjava/lang/String;II)V", (void*)notifyAction_native }, | ||
}; | ||
|
||
int register_android_server_ActivityTriggerService(JNIEnv *env) { | ||
//load and link to the handler library | ||
trigger_handler_lib_init(); | ||
return jniRegisterNativeMethods(env, "com/android/server/ActivityTriggerService", | ||
method_list, NELEM(method_list)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters