Android framework累积

提高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<String[]> 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<String[]> getList(String pkgkey, String signkey) {
		JSONArray jsonArray      = null;
		ArrayList<String[]> 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<String[]>();
			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<AppEntry> mRebuildComparator;
        ArrayList<AppEntry> mRebuildResult;
        ArrayList<AppEntry> 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<AppEntry> getAllApps() {
            synchronized (mEntriesMap) {
                return new ArrayList<>(mAppEntries);
            }
        }

        // Creates a new list of app entries with the given filter and comparator.
        public ArrayList<AppEntry> rebuild(AppFilter filter, Comparator<AppEntry> comparator) {
            return rebuild(filter, comparator, true);
        }

        public ArrayList<AppEntry> rebuild(AppFilter filter, Comparator<AppEntry> 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<AppEntry> 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<AppEntry> apps;
            synchronized (mEntriesMap) {
                apps = new ArrayList<AppEntry>(mAppEntries);
            }

            ArrayList<AppEntry> filteredApps = new ArrayList<AppEntry>();
            
            for (int i=0; i<apps.size(); i++) {
            	 AppEntry entry = apps.get(i);
            	 // add xxx
            	 if (entry != null && (filter == null || filter.filterApp(entry))) {
            		 String pgName = entry.info.packageName;
            		 
            		 if(isAllapps){
            			 synchronized (mEntriesMap) {
	  	                        if (comparator != null) {
	  	                            entry.ensureLabel(mContext);    
	  	                        }
	  	                        filteredApps.add(entry);
	  	                    }
            		 }else{
            			 if(!pgName.startsWith(filterString)){
            				 synchronized (mEntriesMap) {
 		                        if (comparator != null) {
 		                            entry.ensureLabel(mContext);    
 		                        }
 		                        filteredApps.add(entry);
 		                    }
            			 }
            		 }
            	 }
            }

            if (comparator != null) {
                Collections.sort(filteredApps, comparator);
            }

            synchronized (mRebuildSync) {
                if (!mRebuildRequested) {
                    mLastAppList = filteredApps;
                    if (!mRebuildAsync) {
                        mRebuildResult = filteredApps;
                        mRebuildSync.notifyAll();
                    } else {
                        if (!mMainHandler.hasMessages(MainHandler.MSG_REBUILD_COMPLETE, this)) {
                            Message msg = mMainHandler.obtainMessage(MainHandler.MSG_REBUILD_COMPLETE, this);
                            mMainHandler.sendMessage(msg);
                        }
                    }
                }
            }
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        }

        public void release() {
            pause();
            synchronized (mEntriesMap) {
                mSessions.remove(this);
            }
        }
    }

 

修改默认的热点网络共享的名字和密码:

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<Integer> 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<Integer>();
            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<Integer> 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;
    }

待续。。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值