阿里云輕云服務(wù)器可以放多個(gè)網(wǎng)站啊怎么做做網(wǎng)站需要準(zhǔn)備什么
最近要用到這個(gè),所以也花時(shí)間看看。
從分層來(lái)說(shuō),安卓的自啟動(dòng)也分成三種,app的自啟動(dòng),framework服務(wù)的自啟動(dòng),HAL服務(wù)的自啟動(dòng)?,F(xiàn)在簡(jiǎn)單說(shuō)說(shuō)這三種吧。當(dāng)然,我主要關(guān)注的還是最后一種。。。
一 App的自啟動(dòng)
1?AndroidManifest.xml中修改
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2?編寫(xiě)廣播接收器
public class BootCompletedReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {// 啟動(dòng)應(yīng)用的主活動(dòng)Intent activityIntent = new Intent(context, MainActivity.class);activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(activityIntent);// 或者啟動(dòng)服務(wù)Intent serviceIntent = new Intent(context, MyService.class);context.startService(serviceIntent);}}
}
3?在AndroidManifest.xml中注冊(cè)廣播接收器
<receiver android:name=".BootCompletedReceiver" android:enabled="true" android:exported="false"><intent-filter><action android:name="android.intent.action.BOOT_COMPLETED" /><category android:name="android.intent.category.DEFAULT" /></intent-filter>
</receiver>
二 Framework的自啟動(dòng)
基本上和app差不多,有一些細(xì)微修改。
AndroidManifest.xml中定義是這樣的。
<service android:name=".MyService" android:enabled="true" android:exported="false" />
在廣播接收器中啟動(dòng)服務(wù)是這樣的。
@Override
public void onReceive(Context context, Intent intent) {if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {Intent serviceIntent = new Intent(context, MyService.class);context.startService(serviceIntent);}
}
三 Hal service的自啟動(dòng)
1 增加service.rc
service SampleService /system/bin/sampleserviceclass haluser systemgroup system# 如果在rc?件中添加了 'class hal',即歸類(lèi)為hal服務(wù),會(huì)在init的start hal階段通過(guò)hwservice啟動(dòng)所有的hal服務(wù)。
在Android.bp中增加這個(gè)rc文件。
2 增加Selinux權(quán)限
關(guān)于這部分,可以看看我之前寫(xiě)的:SEAndroid學(xué)習(xí)12 -- SELinux-CSDN博客
關(guān)于這個(gè)部分,有兩個(gè)部分,是一個(gè)系統(tǒng)的配置,一個(gè)是服務(wù)的配置。
系統(tǒng)配置:
在瑞芯微的平臺(tái),是這樣獲取路徑的:get_build_var BOARD_SEPOLICY_DIRS
hwservice.te
type vnd_nxpnfc_hwservice, hwservice_manager_type;
hwservice_contexts
vendor.nxp.nxpnfc::INxpNfc (對(duì)照manifest中增加的instance,別寫(xiě)錯(cuò))
u:object_r:vnd_nxpnfc_hwservice:s0
file_contexts
/vendor/bin/hw/vendor\.nxp\.nxpnfc@1\.0-service u:object_r:nxpnfc_hal_exec:s0
服務(wù)配置:
fileservice.te
type nxpnfc_hal, domain;
type nxpnfc_hal_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(nxpnfc_hal)
add_hwservice(nfc, vnd_nxpnfc_hwservice) # 如果是通過(guò)nfc進(jìn)程啟動(dòng)新加的服務(wù),才需要添
加
具體可以參考這個(gè):android 實(shí)現(xiàn)一個(gè)開(kāi)機(jī)自啟動(dòng)的service_android開(kāi)機(jī)自啟動(dòng)service-CSDN博客
下周會(huì)具體做部分工作,到時(shí)候再更新把。。。
參考:
Rockchip_Developer_Guide_Android_SELinux(Sepolicy)_CN.pdf