下面列出了怎么用android.util.LogPrinter的API类实例代码及写法,或者点击链接到github查看源代码。
public void addFilter(F f) {
if (localLOGV) {
Slog.v(TAG, "Adding filter: " + f);
f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Building Lookup Maps:");
}
mFilters.add(f);
int numS = register_intent_filter(f, f.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = register_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
register_intent_filter(f, f.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
register_intent_filter(f, f.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
void removeFilterInternal(F f) {
if (localLOGV) {
Slog.v(TAG, "Removing filter: " + f);
f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Cleaning Lookup Maps:");
}
int numS = unregister_intent_filter(f, f.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = unregister_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
unregister_intent_filter(f, f.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
unregister_intent_filter(f, f.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
private void removeActivity(PackageParser.Activity a, String type) {
mActivities.remove(a.getComponentName());
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " " + type + " "
+ (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel
: a.info.name) + ":");
Log.v(TAG, " Class=" + a.info.name);
}
final int intentsSize = a.intents.size();
for (int j = 0; j < intentsSize; j++) {
PackageParser.ActivityIntentInfo intent = a.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
removeFilter(intent);
}
}
void removeProvider(PackageParser.Provider p) {
mProviders.remove(p.getComponentName());
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " " + (p.info.nonLocalizedLabel != null
? p.info.nonLocalizedLabel
: p.info.name) + ":");
Log.v(TAG, " Class=" + p.info.name);
}
final int intentsSize = p.intents.size();
int j;
for (j = 0; j < intentsSize; j++) {
PackageParser.ProviderIntentInfo intent = p.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
removeFilter(intent);
}
}
void addService(PackageParser.Service s) {
mServices.put(s.getComponentName(), s);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " "
+ (s.info.nonLocalizedLabel != null
? s.info.nonLocalizedLabel : s.info.name) + ":");
Log.v(TAG, " Class=" + s.info.name);
}
final int intentsSize = s.intents.size();
int j;
for (j = 0; j < intentsSize; j++) {
PackageParser.ServiceIntentInfo intent = s.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
if (!intent.debugCheck()) {
Log.w(TAG, "==> For Service " + s.info.name);
}
addFilter(intent);
}
}
void removeService(PackageParser.Service s) {
mServices.remove(s.getComponentName());
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " " + (s.info.nonLocalizedLabel != null
? s.info.nonLocalizedLabel : s.info.name) + ":");
Log.v(TAG, " Class=" + s.info.name);
}
final int intentsSize = s.intents.size();
int j;
for (j = 0; j < intentsSize; j++) {
PackageParser.ServiceIntentInfo intent = s.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
removeFilter(intent);
}
}
public void addFilter(F f) {
if (localLOGV) {
Slog.v(TAG, "Adding filter: " + f);
f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Building Lookup Maps:");
}
mFilters.add(f);
int numS = register_intent_filter(f, f.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = register_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
register_intent_filter(f, f.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
register_intent_filter(f, f.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
void removeFilterInternal(F f) {
if (localLOGV) {
Slog.v(TAG, "Removing filter: " + f);
f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Cleaning Lookup Maps:");
}
int numS = unregister_intent_filter(f, f.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = unregister_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
unregister_intent_filter(f, f.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
unregister_intent_filter(f, f.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
public final void addActivity(PackageParser.Activity a, String type) {
final boolean systemApp = isSystemApp(a.info.applicationInfo);
mActivities.put(a.getComponentName(), a);
if (DEBUG_SHOW_INFO)
Log.v(TAG, " " + type + " "
+ (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":");
if (DEBUG_SHOW_INFO)
Log.v(TAG, " Class=" + a.info.name);
final int NI = a.intents.size();
for (int j = 0; j < NI; j++) {
PackageParser.ActivityIntentInfo intent = a.intents.get(j);
if (!systemApp && intent.getPriority() > 0 && "activity".equals(type)) {
intent.setPriority(0);
Log.w(TAG, "Package " + a.info.applicationInfo.packageName + " has activity " + a.className
+ " with priority > 0, forcing to 0");
}
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
addFilter(intent);
}
}
public final void removeActivity(PackageParser.Activity a, String type) {
mActivities.remove(a.getComponentName());
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " " + type + " "
+ (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":");
Log.v(TAG, " Class=" + a.info.name);
}
final int NI = a.intents.size();
for (int j = 0; j < NI; j++) {
PackageParser.ActivityIntentInfo intent = a.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
removeFilter(intent);
}
}
public final void addActivity(DynamicApkParser.Activity a, String type) {
mActivities.put(a.getComponentName().getClassName(), a);
if (DEBUG_SHOW_INFO)
Log.v(
TAG, " " + type + " " +
(a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":");
if (DEBUG_SHOW_INFO)
Log.v(TAG, " Class=" + a.info.name);
final int NI = a.intents.size();
for (int j=0; j<NI; j++) {
DynamicApkParser.ActivityIntentInfo intent = a.intents.get(j);
if (intent.getPriority() > 0 && "activity".equals(type)) {
intent.setPriority(0);
Log.w(TAG, "Package " + a.info.applicationInfo.packageName + " has activity "
+ a.className + " with priority > 0, forcing to 0");
}
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
}
}
public final void removeActivity(DynamicApkParser.Activity a, String type) {
mActivities.remove(a.getComponentName().getClassName());
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " " + type + " "
+ (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel
: a.info.name) + ":");
Log.v(TAG, " Class=" + a.info.name);
}
final int NI = a.intents.size();
for (int j=0; j<NI; j++) {
DynamicApkParser.ActivityIntentInfo intent = a.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
}
}
public final void addService(DynamicApkParser.Service s) {
mServices.put(s.getComponentName().getClassName(), s);
if (DEBUG_SHOW_INFO)
Log.v(
TAG, " " +
(s.info.nonLocalizedLabel != null ? s.info.nonLocalizedLabel : s.info.name) + ":");
if (DEBUG_SHOW_INFO)
Log.v(TAG, " Class=" + s.info.name);
final int NI = s.intents.size();
for (int j=0; j<NI; j++) {
DynamicApkParser.ServiceIntentInfo intent = s.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
}
}
public final void removeService(DynamicApkParser.Service s, String type) {
mServices.remove(s.getComponentName().getClassName());
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " " + type + " "
+ (s.info.nonLocalizedLabel != null ? s.info.nonLocalizedLabel
: s.info.name) + ":");
Log.v(TAG, " Class=" + s.info.name);
}
final int NI = s.intents.size();
for (int j=0; j<NI; j++) {
DynamicApkParser.ServiceIntentInfo intent = s.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
}
}
public final void addProvider(DynamicApkParser.Provider p) {
mProviders.put(p.getComponentName().getClassName(), p);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " "
+ (p.info.nonLocalizedLabel != null
? p.info.nonLocalizedLabel : p.info.name) + ":");
Log.v(TAG, " Class=" + p.info.name);
}
final int NI = p.intents.size();
int j;
for (j = 0; j < NI; j++) {
DynamicApkParser.ProviderIntentInfo intent = p.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
}
}
public final void removeProvider(DynamicApkParser.Provider p) {
mProviders.remove(p.getComponentName().getClassName());
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " " + (p.info.nonLocalizedLabel != null
? p.info.nonLocalizedLabel : p.info.name) + ":");
Log.v(TAG, " Class=" + p.info.name);
}
final int NI = p.intents.size();
int j;
for (j = 0; j < NI; j++) {
DynamicApkParser.ProviderIntentInfo intent = p.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
}
}
public void addFilter(F f) {
if (localLOGV) {
Slog.v(TAG, "Adding filter: " + f);
f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Building Lookup Maps:");
}
mFilters.add(f);
int numS = register_intent_filter(f, f.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = register_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
register_intent_filter(f, f.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
register_intent_filter(f, f.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
void removeFilterInternal(F f) {
if (localLOGV) {
Slog.v(TAG, "Removing filter: " + f);
f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Cleaning Lookup Maps:");
}
int numS = unregister_intent_filter(f, f.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = unregister_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
unregister_intent_filter(f, f.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
unregister_intent_filter(f, f.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
private void addActivity(PackageParser.Activity a, String type,
List<PackageParser.ActivityIntentInfo> newIntents) {
mActivities.put(a.getComponentName(), a);
if (DEBUG_SHOW_INFO) {
final CharSequence label = a.info.nonLocalizedLabel != null
? a.info.nonLocalizedLabel
: a.info.name;
Log.v(TAG, " " + type + " " + label + ":");
}
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " Class=" + a.info.name);
}
final int intentsSize = a.intents.size();
for (int j = 0; j < intentsSize; j++) {
PackageParser.ActivityIntentInfo intent = a.intents.get(j);
if (newIntents != null && "activity".equals(type)) {
newIntents.add(intent);
}
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
if (!intent.debugCheck()) {
Log.w(TAG, "==> For Activity " + a.info.name);
}
addFilter(intent);
}
}
void addProvider(PackageParser.Provider p) {
if (mProviders.containsKey(p.getComponentName())) {
Slog.w(TAG, "Provider " + p.getComponentName() + " already defined; ignoring");
return;
}
mProviders.put(p.getComponentName(), p);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " "
+ (p.info.nonLocalizedLabel != null
? p.info.nonLocalizedLabel
: p.info.name)
+ ":");
Log.v(TAG, " Class=" + p.info.name);
}
final int intentsSize = p.intents.size();
int j;
for (j = 0; j < intentsSize; j++) {
PackageParser.ProviderIntentInfo intent = p.intents.get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
if (!intent.debugCheck()) {
Log.w(TAG, "==> For Provider " + p.info.name);
}
addFilter(intent);
}
}
@Override
public void onCreate() {
super.onCreate();
Utils.debugLog(TAG, "Creating downloader service.");
HandlerThread thread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
serviceLooper = thread.getLooper();
if (BuildConfig.DEBUG) {
serviceLooper.setMessageLogging(new LogPrinter(Log.DEBUG, ServiceHandler.TAG));
}
serviceHandler = new ServiceHandler(serviceLooper);
localBroadcastManager = LocalBroadcastManager.getInstance(this);
}
@Override
public void handleEvent(AccessibilityEvent event) {
// Avoid processing events when screen is locked
if (_keyguardManager != null) {
boolean locked = _keyguardManager.inKeyguardRestrictedInputMode();
if (locked) {
Log.i(TAG, "Screen locked, skipping overlay check!");
return;
}
}
Log.d(TAG, String.format("New event %s", event.toString()));
_eventCounter.newEvent();
_notifyService.updateNotificationCount(_eventCounter.getLastMinuteEventCount());
if (_resultReceiver != null) {
Bundle bundle = new Bundle();
bundle.putLong("eventCount", _eventCounter.getLastMinuteEventCount());
_resultReceiver.send(ServiceCommunication.MSG_EVENT_COUNT_UPDATE, bundle);
}
// When overlay is detected avoid performing useless computation
if (_overlayState.isHasOverlay() || _overlayState.isPendingUninstall())
return;
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
if (event.getPackageName() == null)
return;
String eventPackage = event.getPackageName().toString();
ComponentName componentName = new ComponentName(
eventPackage,
event.getClassName().toString()
);
ActivityInfo activityInfo = tryGetActivity(componentName);
boolean isActivity = activityInfo != null;
if (isActivity) {
LogPrinter logPrinter = new LogPrinter(Log.DEBUG, TAG);
activityInfo.dump(logPrinter, "");
}
String className = event.getClassName().toString();
// Perform detection
boolean parentAvailable = event.getSource() != null ? event.getSource().getParent() != null : false;
Log.d(TAG, String.format("Collected info isActivity %s, parentAvailable: %s", String.valueOf(isActivity), String.valueOf(parentAvailable)));
if (_overlayState.getIgnoreOncePackage().equals(eventPackage)) {
Log.d(TAG, String.format("Package %s ignored once", eventPackage));
} else if (eventPackage.equals(previousEventPackage)) {
Log.d(TAG, String.format("Last two event have the same package %s, skipping check!", eventPackage));
} else if (_layoutClasses.contains(className) && !isActivity && !parentAvailable) {
Log.d(TAG, String.format("Detected suspicious class %s without activity and parent for process %s, checking whitelist", className, eventPackage));
if (!checkWhitelistHit(eventPackage)) {
Log.d(TAG, "No whitelist entry found");
if (checkSuspectedApps(eventPackage)) {
Log.d(TAG, String.format("******* VIEW OVERLAY DETECTED!!!"));
_overlayState.setOffender(eventPackage);
_overlayState.setProcess(_currentProcess);
_notifyService.processOverlayState(_overlayState);
}
} else {
Log.d(TAG, "Whitelist hit skipping!");
}
} else if (isActivity && activityInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE && !parentAvailable) {
Log.d(TAG, String.format("Detected suspicious activity %s with single instance flag, checking whitelist", activityInfo.packageName));
if (!checkWhitelistHit(eventPackage)) {
Log.d(TAG, "No whitelist entry found");
if (checkSuspectedApps(eventPackage)) {
Log.d(TAG, String.format("******* ACTIVITY OVERLAY DETECTED!!!"));
_overlayState.setOffender(eventPackage);
_overlayState.setProcess(_currentProcess);
_notifyService.processOverlayState(_overlayState);
}
} else {
Log.d(TAG, "Whitelist hit skipping!");
}
}
previousEventPackage = eventPackage;
}
}