提高APK的进程级别:
....\frameworks\base\services\core\java\com\android\server\am\ActivityManagerSerice.java
ActivityManagerSerice类里 systemReady() 方法添加如下代码:
synchronized(this) {
if (mSystemReady) {
// If we're done calling all the receivers, run the next "boot phase" passed in by the SystemServer
if (goingCallback != null) {
goingCallback.run();
}
return;
}
// add start
starthService();
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AUTO_TIME, 1);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AUTO_TIME_GPS, 1);
Settings.System.putInt(mContext.getContentResolver(), Settings.System.AUTO_TIME_GPS, 1);
String oper = SystemProperties.get("ro.operator.oper");
if (oper != null) {
if (oper.startsWith("xxxx")) {
// dosomething
}
}
String model = Build.MODEL;
if (model != null) {
if (model.equals("CarL")) {
Settings.System.putInt(mContext.getContentResolver(), "xxxxxxx", 0);
int tasWallpaperIndex = SystemProperties.getInt("ro.tas.wallpaper", 0);
Settings.System.putInt(mContext.getContentResolver(), "xxxxxxxx", tasWallpaperIndex);
}
}
只能安装指定的APK
。。。。。。。。\frameworks\base\services\core\java\com\android\server\pm\PackageManagerServicejava
PackageManagerServicejava 里的 installNewPackageLIF()方法里添加:
String pkgName = pkg.packageName;
if(mWhiteList && !isSupportedInstall(pkg)){
res.setError(PackageManager.INSTALL_FAILED_TEST_ONLY, "xxx force return for white list, package: " + pkgName);
return;
}
private static boolean mWhiteList = "yes".equals(SystemProperties.get("ro.xxxx", "no"));;
/**
* 只有在名单中的包才可以安装
*/
private boolean isSupportedInstall(PackageParser.Package pkg) {
String filePath = getFilePath();
if (filePath == null || !(new File(filePath).exists())) return true;
List appPathList = getList("packeName", "sign");
if(appPathList != null && appPathList.size() > 0 && pkg != null){
for(int i=0; i < appPathList.size(); i++){
try{
String pkgName = pkg.packageName;
if (pkgName != null && pkgName.equals(appPathList.get(i)[0])) {
String sign = getSignatureString(pkg.mSignatures[0], "SHA1");
if (sign != null && sign.equalsIgnoreCase(appPathList.get(i)[1])) {
return true;
}
}
} catch (Exception e){
Slog.e(TAG, "exception " + e.getMessage());
}
}
}
return false;
}
private ArrayList getList(String pkgkey, String signkey) {
JSONArray jsonArray = null;
ArrayList list = null;
String filePath = getFilePath();
try {
FileInputStream fis = new FileInputStream(new File(filePath));
byte[] data = new byte[fis.available()];
fis.read(data);
fis.close();
jsonArray = new JSONArray(new String(data));
list = new ArrayList();
if (jsonArray != null && jsonArray.length() > 0) {
for (int i = 0; i < jsonArray.length(); i++) {
try {
JSONObject object = (JSONObject) jsonArray.get(i);
String[] values = new String[2];
values[0] = (String) object.get(pkgkey);
values[1] = (String) object.get(signkey);
list.add(values);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
} catch (FileNotFoundException e) {
jsonArray = new JSONArray();
Slog.e(TAG, " FileNotFoundException: " + e.getMessage());
} catch (IOException e) {
jsonArray = new JSONArray();
Slog.e(TAG, " IOException: " + e.getMessage());
} catch (JSONException e) {
jsonArray = new JSONArray();
Slog.e(TAG, " JSONException: " + e.getMessage());
}
return list;
}
/**
* 获取相应的类型的字符串(把签名的byte[]信息转换成16进制)
*/
private String getSignatureString(Signature sig, String type) {
byte[] hexBytes = sig.toByteArray();
String fingerprint = "error!";
Slog.d(TAG, "+ fingerprint: " + fingerprint);
try {
MessageDigest digest = MessageDigest.getInstance(type);
if (digest != null) {
byte[] digestBytes = digest.digest(hexBytes);
StringBuilder sb = new StringBuilder();
for (byte digestByte : digestBytes) {
sb.append((Integer.toHexString((digestByte & 0xFF) | 0x100)).substring(1, 3));
}
fingerprint = sb.toString();
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
Slog.d(TAG, " fingerprint: " + fingerprint);
return fingerprint;
}
private String getFilePath(){
return android.provider.Settings.System.getString(mContext.getContentResolver(), "PkgWhiteList");
}
isProtectedBroadcast里添加“
@Override
public boolean isProtectedBroadcast(String actionName) {
synchronized (mPackages) {
if (mProtectedBroadcasts.contains(actionName)) { return true;
} else if (actionName != null) { // add
if (actionName.startsWith("android.net.netmon.lingerExpired")
|| actionName.startsWith("com.android.server.sip.SipWakeupTimer")
|| actionName.startsWith("com.android.internal.telephony.data-reconnect")
|| actionName.startsWith("android.net.netmon.launchCaptivePortalApp")) {
return true;
}
}
}
return false;
}
private boolean isRmtProtectedBroadcast(String actionName) {
return actionName.startsWith("com.xxxx") || actionName.startsWith("com.android.rmt")|| actionName.startsWith("cn.kuwo.kwmusicauto.action")|| actionName.startsWith("yecon.intent.action.AIRPLANE_MODE");
}
Settings里去掉APK的显示:
frameworks/base/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
private void isStatus() {
isAllapps = Settings.System.getInt(mContext.getContentResolver(), "show_apps", -1) > 0;
}
public class Session {
final Callbacks mCallbacks;
boolean mResumed;
// Rebuilding of app list. Synchronized on mRebuildSync.
final Object mRebuildSync = new Object();
boolean mRebuildRequested;
boolean mRebuildAsync;
AppFilter mRebuildFilter;
Comparator mRebuildComparator;
ArrayList mRebuildResult;
ArrayList mLastAppList;
boolean mRebuildForeground;
Session(Callbacks callbacks) {
mCallbacks = callbacks;
}
public void resume() {
synchronized (mEntriesMap) {
if (!mResumed) {
mResumed = true;
mSessionsChanged = true;
// add zzz
isStatus();
// add end
doResumeIfNeededLocked();
}
}
}
public void pause() {
synchronized (mEntriesMap) {
if (mResumed) {
mResumed = false;
mSessionsChanged = true;
mBackgroundHandler.removeMessages(BackgroundHandler.MSG_REBUILD_LIST, this);
doPauseIfNeededLocked();
}
}
}
public ArrayList getAllApps() {
synchronized (mEntriesMap) {
return new ArrayList<>(mAppEntries);
}
}
// Creates a new list of app entries with the given filter and comparator.
public ArrayList rebuild(AppFilter filter, Comparator comparator) {
return rebuild(filter, comparator, true);
}
public ArrayList rebuild(AppFilter filter, Comparator comparator, boolean foreground) {
synchronized (mRebuildSync) {
synchronized (mEntriesMap) {
mRebuildingSessions.add(this);
mRebuildRequested = true;
mRebuildAsync = false;
mRebuildFilter = filter;
mRebuildComparator = comparator;
mRebuildForeground = foreground;
mRebuildResult = null;
if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_REBUILD_LIST)) {
Message msg = mBackgroundHandler.obtainMessage(BackgroundHandler.MSG_REBUILD_LIST);
mBackgroundHandler.sendMessage(msg);
}
}
// We will wait for .25s for the list to be built.
long waitend = SystemClock.uptimeMillis()+250;
while (mRebuildResult == null) {
long now = SystemClock.uptimeMillis();
if (now >= waitend) {
break;
}
try {
mRebuildSync.wait(waitend - now);
} catch (InterruptedException e) {
}
}
mRebuildAsync = true;
return mRebuildResult;
}
}
void handleRebuildList() {
AppFilter filter;
Comparator comparator;
synchronized (mRebuildSync) {
if (!mRebuildRequested) return;
filter = mRebuildFilter;
comparator = mRebuildComparator;
mRebuildRequested = false;
mRebuildFilter = null;
mRebuildComparator = null;
if (mRebuildForeground) {
Process.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
mRebuildForeground = false;
}
}
if (filter != null) {
filter.init();
}
List apps;
synchronized (mEntriesMap) {
apps = new ArrayList(mAppEntries);
}
ArrayList filteredApps = new ArrayList();
for (int i=0; i
修改默认的热点网络共享的名字和密码:
frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiApConfigStore.java
WifiApConfigStore里修改
private static final String TAG = "WifiApConfigStore";
private static final String DEFAULT_AP_CONFIG_FILE = Environment.getDataDirectory() + "/misc/wifi/softap.conf";
private static final int AP_CONFIG_FILE_VERSION = 2;
private WifiConfiguration mWifiApConfig = null;
private ArrayList mAllowed2GChannel = null;
private final Context mContext;
private final String mApConfigFile;
private final BackupManagerProxy mBackupManagerProxy;
WifiApConfigStore(Context context, BackupManagerProxy backupManagerProxy) {
this(context, backupManagerProxy, DEFAULT_AP_CONFIG_FILE);
}
WifiApConfigStore(Context context, BackupManagerProxy backupManagerProxy, String apConfigFile) {
mContext = context;
mBackupManagerProxy = backupManagerProxy;
mApConfigFile = apConfigFile;
String ap2GChannelListStr = mContext.getResources().getString(R.string.config_wifi_framework_sap_2G_channel_list);
if (ap2GChannelListStr != null) {
mAllowed2GChannel = new ArrayList();
String channelList[] = ap2GChannelListStr.split(",");
for (String tmp : channelList) {
mAllowed2GChannel.add(Integer.parseInt(tmp));
}
}
/* Load AP configuration from persistent storage. */
mWifiApConfig = loadApConfiguration(mApConfigFile);
if (mWifiApConfig == null) {
/* Use default configuration. */
Log.d(TAG, "---Fallback to use default AP configuration------>");
mWifiApConfig = getDefaultApConfiguration();
/* Save the default configuration to persistent storage. */
writeApConfiguration(mApConfigFile, mWifiApConfig);
}
}
/**
* Return the current soft access point configuration.
*/
public synchronized WifiConfiguration getApConfiguration() {
return mWifiApConfig;
}
/**
* Update the current soft access point configuration.
* Restore to default AP configuration if null is provided.
* This can be invoked under context of binder threads (WifiManager.setWifiApConfiguration)
* and WifiStateMachine thread (CMD_START_AP).
*/
public synchronized void setApConfiguration(WifiConfiguration config) {
if (config == null) {
mWifiApConfig = getDefaultApConfiguration();
} else {
mWifiApConfig = config;
}
writeApConfiguration(mApConfigFile, mWifiApConfig);
// Stage the backup of the SettingsProvider package which backs this up
mBackupManagerProxy.notifyDataChanged();
}
public ArrayList getAllowed2GChannel() {
return mAllowed2GChannel;
}
// Load AP configuration from persistent storage.
private static WifiConfiguration loadApConfiguration(final String filename) {
WifiConfiguration config = null;
DataInputStream in = null;
try {
config = new WifiConfiguration();
in = new DataInputStream(new BufferedInputStream(new FileInputStream(filename)));
int version = in.readInt();
if ((version != 1) && (version != 2)) {
Log.e(TAG, "---Bad version on hotspot configuration file---->");
return null;
}
// zgy
String ssid = in.readUTF();
if(ssid.startsWith("Android")) {
config.SSID = Build.MODEL;
Log.e(TAG, "---ssid-111->" + config.SSID);
}else{
config.SSID = ssid;
Log.e(TAG, "---ssid-222->" + config.SSID);
}
//
if (version >= 2) {
config.apBand = in.readInt();
config.apChannel = in.readInt();
}
int authType = in.readInt();
config.allowedKeyManagement.set(authType);
if (authType != KeyMgmt.NONE) {
// xxx
String pass = in.readUTF();
if (isNumeric(pass)) { // TextUtils.isDigitsOnly(pass)
config.preSharedKey = pass;
Log.e(TAG, "---pass-333->" + config.preSharedKey);
} else {
config.preSharedKey = "cmcc1234";
Log.e(TAG, "---pass-444->" + config.preSharedKey);
}
//
}
} catch (IOException e) {
Log.e(TAG, "---Error reading hotspot configuration-->" + e);
config = null;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
Log.e(TAG, "Error closing hotspot configuration during read" + e);
}
}
}
return config;
}
private static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
/**
* Write AP configuration to persistent storage.
*/
private static void writeApConfiguration(final String filename, final WifiConfiguration config) {
try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)))) {
out.writeInt(AP_CONFIG_FILE_VERSION);
out.writeUTF(config.SSID);
out.writeInt(config.apBand);
out.writeInt(config.apChannel);
int authType = config.getAuthType();
out.writeInt(authType);
if (authType != KeyMgmt.NONE) {
out.writeUTF(config.preSharedKey);
}
Log.e(TAG, "---write-SSID-->" + config.SSID + "--key-->" + config.preSharedKey);
} catch (IOException e) {
Log.e(TAG, "--Error writing hotspot configuration--->" + e);
}
}
/**
* Generate a default WPA2 based configuration with a random password.
* We are changing the Wifi Ap configuration storage from secure settings to a
* flat file accessible only by the system. A WPA2 based default configuration
* will keep the device secure after the update.
*/
private WifiConfiguration getDefaultApConfiguration() {
WifiConfiguration config = new WifiConfiguration();
IWifiFwkExt wifiFwkExt = MPlugin.createInstance(IWifiFwkExt.class.getName(), mContext);
if (SystemProperties.get("ro.mtk_bsp_package").equals("1")) {
if (wifiFwkExt != null) {
config.SSID = wifiFwkExt.getApDefaultSsid();
Log.e(TAG, "---Default-111->" + wifiFwkExt.getApDefaultSsid());
} else {
config.SSID = Build.MODEL; // mContext.getResources().getString(R.string.wifi_tether_configure_ssid_default);
Log.e(TAG, "---Default-222->" + Build.MODEL);
}
} else {
config.SSID = Build.MODEL; /* com.mediatek.custom.CustomProperties.getString(com.mediatek.custom.CustomProperties.MODULE_WLAN, com.mediatek.custom.CustomProperties.SSID, mContext.getString(R.string.wifi_tether_configure_ssid_default)); */
Log.e(TAG, "---Default-333->" + Build.MODEL);
if (wifiFwkExt != null && wifiFwkExt.needRandomSsid()) {
// Random random = new Random(SystemClock.elapsedRealtime());
config.SSID = "cmcc1234";// config.SSID + random.nextInt(1000);
Log.e(TAG, "---Default-444->" + config.SSID);
}
}
config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
// String randomUUID = UUID.randomUUID().toString();
config.preSharedKey = "cmcc1234"; //randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
Log.e(TAG, "---Default-555->" + config.preSharedKey);
return config;
}
待续。。。。。。