Skip to content

Commit

Permalink
[hapjs-platform#645]系统应用判断条件增加FLAG_UPDATED_SYSTEM_APP,并统一使用PackageUti…
Browse files Browse the repository at this point in the history
…ls进行判断

Signed-off-by: chaihua1 <[email protected]>
  • Loading branch information
charles-chai committed Jan 4, 2024
1 parent 0d0ebb4 commit 4a61a1b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* Copyright (c) 2021, the hapjs-platform Project Contributors
* Copyright (c) 2021-present, the hapjs-platform Project Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.hapjs.features.geolocation.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
Expand Down Expand Up @@ -81,25 +80,4 @@ public static String getAppVersionName(Context context, String packageName) {
}
return null;
}

public static boolean isSystemApp(Context context, String remotePkg) {
if (context == null) {
return false;
}
PackageManager pm = context.getPackageManager();
if (pm == null) {
return false;
}

ApplicationInfo applicationInfo = null;
try {
applicationInfo = pm.getApplicationInfo(remotePkg, PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "isSystemApp: ", e);
}
return applicationInfo != null
&& (applicationInfo.flags
& (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP))
!= 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/*
* Copyright (c) 2022, the hapjs-platform Project Contributors
* Copyright (c) 2022-present, the hapjs-platform Project Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.hapjs.analyzer.monitors;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;

import org.hapjs.analyzer.monitors.abs.AbsTimerMonitor;
import org.hapjs.common.utils.FileUtils;
import org.hapjs.common.utils.PackageUtils;
import org.hapjs.runtime.Runtime;

import java.io.BufferedReader;
Expand All @@ -41,18 +40,7 @@ private static boolean canAccessProcStatFile() {

private static boolean isSystemApp() {
Context context = Runtime.getInstance().getContext();
if (context == null) {
return false;
}
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
return packageInfo != null &&
packageInfo.applicationInfo != null &&
((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
} catch (Exception e) {
// ignore
}
return false;
return PackageUtils.isSystemPackage(context, context.getPackageName());
}

public CpuMonitor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static boolean isSystemPackage(Context context, String packageName) {
}
try {
PackageInfo pi = context.getPackageManager().getPackageInfo(packageName, 0);
return pi != null && (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
return pi != null && (pi.applicationInfo.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
} catch (PackageManager.NameNotFoundException e) {
// ignored
}
Expand Down

0 comments on commit 4a61a1b

Please sign in to comment.