@Override public AppInfo createFromParcel(Parcel source) { return new AppInfo(source); }
@Override public void onServiceConnected(ComponentName name, IBinder service) { Log.e(getLocalClassName(), "完成绑定aidlServer的AIDLService服务"); messageCenter = ICheckAppInfoManager.Stub.asInterface(service); mBound = true; if (messageCenter != null) { try { //链接成功 Toast.makeText(SetAppActivity.this,"链接成功",Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } }
@Override public List<AppInfo> getAppInfo(String sign) throws RemoteException { List<AppInfo> list=new ArrayList<>(); String aidlCheckAppInfoSign = AppToolUtils.getAidlCheckAppInfoSign(); LogUtils.e("AppInfoService--AppInfoService",aidlCheckAppInfoSign+"-------------"+sign); if(!aidlCheckAppInfoSign.equals(sign)){ return list; } list.add(new AppInfo("app版本号(versionName)", BuildConfig.VERSION_NAME)); list.add(new AppInfo("app版本名称(versionCode)", BuildConfig.VERSION_CODE+"")); list.add(new AppInfo("打包时间", BuildConfig.BUILD_TIME)); list.add(new AppInfo("app包名", getPackageName())); list.add(new AppInfo("app作者", SPUtils.getInstance(Constant.SP_NAME).getString("name","杨充"))); list.add(new AppInfo("app渠道", SPUtils.getInstance(Constant.SP_NAME).getString("channel"))); list.add(new AppInfo("token", SPUtils.getInstance(Constant.SP_NAME).getString("token"))); list.add(new AppInfo("App签名", AppToolUtils.getSingInfo(getApplicationContext(), getPackageName(), AppToolUtils.SHA1))); return list; }
switch (type){ case SET_TOKEN: isSuccess=messageCenter.setToken(Utils.getSign(packName),content); break; case SET_CHANNEL: isSuccess=messageCenter.setChannel(Utils.getSign(packName),content); break; case SET_AUTHOR: isSuccess=messageCenter.setAppAuthorName(Utils.getSign(packName),content); break;
private void getAppInfo() { //如果与服务端的连接处于未连接状态,则尝试连接 if (!mBound) { attemptToBindService(); Toast.makeText(this, "当前与服务端处于未连接状态,正在尝试重连,请稍后再试", Toast.LENGTH_SHORT).show(); return; } if (messageCenter == null) { return; } try { List<AppInfo> info = messageCenter.getAppInfo(Utils.getSign(packName)); if(info==null || (info.size()==0)){ Toast.makeText(this, "无法获取数据,可能是签名错误!", Toast.LENGTH_SHORT).show(); }else { mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); FirstAdapter adapter = new FirstAdapter(info, this); mRecyclerView.setAdapter(adapter); adapter.setOnItemClickListener(new FirstAdapter.OnItemClickListener() { @Override public void onItemClick(View view, int position) { } }); } } catch (RemoteException e) { e.printStackTrace(); } }
@Override public void onServiceConnected(ComponentName name, IBinder service) { ToastUtil.showToast(MainActivity.this,"完成绑定aidlServer的AIDLService服务"); Log.e(getLocalClassName(), "完成绑定aidlServer的AIDLService服务"); //使用IAppInfoManager.Stub.asInterface()方法获取服务器端返回的IBinder对象 //将IBinder对象传换成了mAIDL_Service接口对象 messageCenter = ICheckAppInfoManager.Stub.asInterface(service); mBound = true; if (messageCenter != null) { try { //链接成功 Toast.makeText(MainActivity.this,"链接成功",Toast.LENGTH_SHORT).show(); // 在创建ServiceConnection的匿名类中的onServiceConnected方法中 // 设置死亡代理 //messageCenter.asBinder().linkToDeath(deathRecipient, 0); } catch (Exception e) { e.printStackTrace(); } } } };