新增aidl服务模拟
Showing
12 changed files
with
687 additions
and
4 deletions
... | @@ -4,10 +4,10 @@ | ... | @@ -4,10 +4,10 @@ |
4 | <selectionStates> | 4 | <selectionStates> |
5 | <SelectionState runConfigName="app"> | 5 | <SelectionState runConfigName="app"> |
6 | <option name="selectionMode" value="DROPDOWN" /> | 6 | <option name="selectionMode" value="DROPDOWN" /> |
7 | <DropdownSelection timestamp="2024-10-12T05:40:06.328823Z"> | 7 | <DropdownSelection timestamp="2024-10-14T01:44:33.742803Z"> |
8 | <Target type="DEFAULT_BOOT"> | 8 | <Target type="DEFAULT_BOOT"> |
9 | <handle> | 9 | <handle> |
10 | <DeviceId pluginId="Default" identifier="serial=0123456789;connection=725ee2fc" /> | 10 | <DeviceId pluginId="LocalEmulator" identifier="path=/Users/bohu/.android/avd/Pixel_Tablet_API_31.avd" /> |
11 | </handle> | 11 | </handle> |
12 | </Target> | 12 | </Target> |
13 | </DropdownSelection> | 13 | </DropdownSelection> | ... | ... |
... | @@ -9,6 +9,7 @@ | ... | @@ -9,6 +9,7 @@ |
9 | <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> | 9 | <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> |
10 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | 10 | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> |
11 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | 11 | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
12 | <permission android:name="com.android.smart.terminal.iptv.aidl.SERVICES" android:protectionLevel="normal"/> | ||
12 | 13 | ||
13 | <application | 14 | <application |
14 | android:allowBackup="true" | 15 | android:allowBackup="true" |
... | @@ -30,6 +31,11 @@ | ... | @@ -30,6 +31,11 @@ |
30 | <category android:name="android.intent.category.LAUNCHER" /> | 31 | <category android:name="android.intent.category.LAUNCHER" /> |
31 | </intent-filter> | 32 | </intent-filter> |
32 | </activity> | 33 | </activity> |
34 | <service android:exported="true" android:name="com.android.smart.terminal.iptv.aidl.ServiceCfg"> | ||
35 | <intent-filter> | ||
36 | <action android:name="com.android.smart.terminal.iptv.aidl.ServiceCfg"/> | ||
37 | </intent-filter> | ||
38 | </service> | ||
33 | </application> | 39 | </application> |
34 | 40 | ||
35 | </manifest> | 41 | </manifest> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
app/src/main/assets/iptv_param.json
0 → 100644
1 | { | ||
2 | "iptvauthurl": "1http://epg.itv.cq.cn:8080/iptvepg/platform/index.jsp", | ||
3 | "iptvaccount": "kdspb2", | ||
4 | "userid": "kdspb2", | ||
5 | "iptvpassword": "159357", | ||
6 | "stbid": "0010059900E06810042094D505F12A7E", | ||
7 | "usertoken": "IlrUGIlrUG17tYxUgfawMrNRAmf8XV7S", | ||
8 | "epgdomain": "http://172.23.88.137:33200/EPG/jsp/xinaishangbanmuban/en/Category.jsp", | ||
9 | "epginfo": "", | ||
10 | "epggroupnmb": "xinaishangbanmuban", | ||
11 | "usergroupnmb": "717", | ||
12 | "productmodel": "", | ||
13 | "terminaltype": "", | ||
14 | "areaid": "", | ||
15 | "countyid": "", | ||
16 | "romversion": "", | ||
17 | "terminalversion": "", | ||
18 | "mac": "", | ||
19 | "iptvstate": "", | ||
20 | "ottcp": "", | ||
21 | "sessionid": "DF10A297F8449B9526B58811497FC4B4" | ||
22 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/src/main/assets/livechannels.json
0 → 100644
This diff is collapsed.
Click to expand it.
1 | package com.android.smart.terminal.iptv.aidl; | ||
2 | |||
3 | import android.os.Binder; | ||
4 | import android.os.IBinder; | ||
5 | import android.os.IInterface; | ||
6 | import android.os.Parcel; | ||
7 | import android.os.RemoteException; | ||
8 | //aidl接口 | ||
9 | public interface IServiceCfg extends IInterface { | ||
10 | |||
11 | boolean getBoolean(String key, boolean defValue) throws RemoteException; | ||
12 | int getInt(String key, int defValue) throws RemoteException; | ||
13 | String getString(String key, String defValue) throws RemoteException; | ||
14 | boolean putBoolean(String key, boolean value) throws RemoteException; | ||
15 | boolean putInt(String key, int value) throws RemoteException; | ||
16 | boolean putString(String key, String value) throws RemoteException; | ||
17 | |||
18 | abstract class Stub extends Binder implements IServiceCfg { | ||
19 | |||
20 | private static final String DESCRIPTOR = "com.android.smart.terminal.iptv.aidl.IServiceCfg"; | ||
21 | static final int TRANSACTION_getBoolean = 6; | ||
22 | static final int TRANSACTION_getInt = 5; | ||
23 | static final int TRANSACTION_getString = 4; | ||
24 | static final int TRANSACTION_putBoolean = 3; | ||
25 | static final int TRANSACTION_putInt = 2; | ||
26 | static final int TRANSACTION_putString = 1; | ||
27 | |||
28 | public Stub() { | ||
29 | this.attachInterface(this, DESCRIPTOR); | ||
30 | } | ||
31 | |||
32 | @Override | ||
33 | public IBinder asBinder() { | ||
34 | return this; | ||
35 | } | ||
36 | |||
37 | public static IServiceCfg asInterface(IBinder obj) { | ||
38 | if (obj == null) return null; | ||
39 | IInterface iin = obj.queryLocalInterface(DESCRIPTOR); | ||
40 | return (iin instanceof IServiceCfg) ? (IServiceCfg) iin : new Proxy(obj); | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { | ||
45 | switch (code) { | ||
46 | case TRANSACTION_putString: | ||
47 | data.enforceInterface(DESCRIPTOR); | ||
48 | boolean resultPutString = putString(data.readString(), data.readString()); | ||
49 | reply.writeNoException(); | ||
50 | reply.writeInt(resultPutString ? 1 : 0); | ||
51 | return true; | ||
52 | |||
53 | case TRANSACTION_putInt: | ||
54 | data.enforceInterface(DESCRIPTOR); | ||
55 | boolean resultPutInt = putInt(data.readString(), data.readInt()); | ||
56 | reply.writeNoException(); | ||
57 | reply.writeInt(resultPutInt ? 1 : 0); | ||
58 | return true; | ||
59 | |||
60 | case TRANSACTION_putBoolean: | ||
61 | data.enforceInterface(DESCRIPTOR); | ||
62 | boolean resultPutBoolean = putBoolean(data.readString(), data.readInt() != 0); | ||
63 | reply.writeNoException(); | ||
64 | reply.writeInt(resultPutBoolean ? 1 : 0); | ||
65 | return true; | ||
66 | |||
67 | case TRANSACTION_getString: | ||
68 | data.enforceInterface(DESCRIPTOR); | ||
69 | String resultGetString = getString(data.readString(), data.readString()); | ||
70 | reply.writeNoException(); | ||
71 | reply.writeString(resultGetString); | ||
72 | return true; | ||
73 | |||
74 | case TRANSACTION_getInt: | ||
75 | data.enforceInterface(DESCRIPTOR); | ||
76 | int resultGetInt = getInt(data.readString(), data.readInt()); | ||
77 | reply.writeNoException(); | ||
78 | reply.writeInt(resultGetInt); | ||
79 | return true; | ||
80 | |||
81 | case TRANSACTION_getBoolean: | ||
82 | data.enforceInterface(DESCRIPTOR); | ||
83 | boolean resultGetBoolean = getBoolean(data.readString(), data.readInt() != 0); | ||
84 | reply.writeNoException(); | ||
85 | reply.writeInt(resultGetBoolean ? 1 : 0); | ||
86 | return true; | ||
87 | |||
88 | case 1598968902: // Interface descriptor | ||
89 | reply.writeString(DESCRIPTOR); | ||
90 | return true; | ||
91 | |||
92 | default: | ||
93 | return super.onTransact(code, data, reply, flags); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | private static class Proxy implements IServiceCfg { | ||
98 | private final IBinder mRemote; | ||
99 | |||
100 | Proxy(IBinder remote) { | ||
101 | mRemote = remote; | ||
102 | } | ||
103 | |||
104 | @Override | ||
105 | public IBinder asBinder() { | ||
106 | return mRemote; | ||
107 | } | ||
108 | |||
109 | @Override | ||
110 | public boolean getBoolean(String key, boolean defValue) throws RemoteException { | ||
111 | Parcel data = Parcel.obtain(); | ||
112 | Parcel reply = Parcel.obtain(); | ||
113 | boolean result; | ||
114 | try { | ||
115 | data.writeInterfaceToken(DESCRIPTOR); | ||
116 | data.writeString(key); | ||
117 | data.writeInt(defValue ? 1 : 0); | ||
118 | mRemote.transact(TRANSACTION_getBoolean, data, reply, 0); | ||
119 | reply.readException(); | ||
120 | result = reply.readInt() != 0; | ||
121 | } finally { | ||
122 | reply.recycle(); | ||
123 | data.recycle(); | ||
124 | } | ||
125 | return result; | ||
126 | } | ||
127 | |||
128 | @Override | ||
129 | public int getInt(String key, int defValue) throws RemoteException { | ||
130 | Parcel data = Parcel.obtain(); | ||
131 | Parcel reply = Parcel.obtain(); | ||
132 | int result; | ||
133 | try { | ||
134 | data.writeInterfaceToken(DESCRIPTOR); | ||
135 | data.writeString(key); | ||
136 | data.writeInt(defValue); | ||
137 | mRemote.transact(TRANSACTION_getInt, data, reply, 0); | ||
138 | reply.readException(); | ||
139 | result = reply.readInt(); | ||
140 | } finally { | ||
141 | reply.recycle(); | ||
142 | data.recycle(); | ||
143 | } | ||
144 | return result; | ||
145 | } | ||
146 | |||
147 | @Override | ||
148 | public String getString(String key, String defValue) throws RemoteException { | ||
149 | Parcel data = Parcel.obtain(); | ||
150 | Parcel reply = Parcel.obtain(); | ||
151 | String result; | ||
152 | try { | ||
153 | data.writeInterfaceToken(DESCRIPTOR); | ||
154 | data.writeString(key); | ||
155 | data.writeString(defValue); | ||
156 | mRemote.transact(TRANSACTION_getString, data, reply, 0); | ||
157 | reply.readException(); | ||
158 | result = reply.readString(); | ||
159 | } finally { | ||
160 | reply.recycle(); | ||
161 | data.recycle(); | ||
162 | } | ||
163 | return result; | ||
164 | } | ||
165 | |||
166 | @Override | ||
167 | public boolean putBoolean(String key, boolean value) throws RemoteException { | ||
168 | Parcel data = Parcel.obtain(); | ||
169 | Parcel reply = Parcel.obtain(); | ||
170 | boolean result; | ||
171 | try { | ||
172 | data.writeInterfaceToken(DESCRIPTOR); | ||
173 | data.writeString(key); | ||
174 | data.writeInt(value ? 1 : 0); | ||
175 | mRemote.transact(TRANSACTION_putBoolean, data, reply, 0); | ||
176 | reply.readException(); | ||
177 | result = reply.readInt() != 0; | ||
178 | } finally { | ||
179 | reply.recycle(); | ||
180 | data.recycle(); | ||
181 | } | ||
182 | return result; | ||
183 | } | ||
184 | |||
185 | @Override | ||
186 | public boolean putInt(String key, int value) throws RemoteException { | ||
187 | Parcel data = Parcel.obtain(); | ||
188 | Parcel reply = Parcel.obtain(); | ||
189 | boolean result; | ||
190 | try { | ||
191 | data.writeInterfaceToken(DESCRIPTOR); | ||
192 | data.writeString(key); | ||
193 | data.writeInt(value); | ||
194 | mRemote.transact(TRANSACTION_putInt, data, reply, 0); | ||
195 | reply.readException(); | ||
196 | result = reply.readInt() != 0; | ||
197 | } finally { | ||
198 | reply.recycle(); | ||
199 | data.recycle(); | ||
200 | } | ||
201 | return result; | ||
202 | } | ||
203 | |||
204 | @Override | ||
205 | public boolean putString(String key, String value) throws RemoteException { | ||
206 | Parcel data = Parcel.obtain(); | ||
207 | Parcel reply = Parcel.obtain(); | ||
208 | boolean result; | ||
209 | try { | ||
210 | data.writeInterfaceToken(DESCRIPTOR); | ||
211 | data.writeString(key); | ||
212 | data.writeString(value); | ||
213 | mRemote.transact(TRANSACTION_putString, data, reply, 0); | ||
214 | reply.readException(); | ||
215 | result = reply.readInt() != 0; | ||
216 | } finally { | ||
217 | reply.recycle(); | ||
218 | data.recycle(); | ||
219 | } | ||
220 | return result; | ||
221 | } | ||
222 | } | ||
223 | } | ||
224 | } |
1 | package com.android.smart.terminal.iptv.aidl; | ||
2 | |||
3 | import android.app.Service; | ||
4 | import android.content.Intent; | ||
5 | import android.os.IBinder; | ||
6 | import android.os.RemoteException; | ||
7 | import android.text.TextUtils; | ||
8 | import android.util.Log; | ||
9 | import org.json.JSONArray; | ||
10 | import org.json.JSONException; | ||
11 | import org.json.JSONObject; | ||
12 | import com.android.smart.terminal.iptv.aidl.IServiceCfg.Stub; | ||
13 | import com.topdraw.iptvlaunchertest.IptvConfig; | ||
14 | import com.topdraw.iptvlaunchertest.TestConfig; | ||
15 | |||
16 | public class ServiceCfg extends Service { | ||
17 | private static final String TAG = "ServiceCfg"; | ||
18 | private final Stub mBinder; | ||
19 | private IptvConfig mConfig; | ||
20 | |||
21 | public ServiceCfg() { | ||
22 | this.mConfig = null; | ||
23 | this.mBinder = new Stub() { | ||
24 | @Override | ||
25 | public boolean getBoolean(String key, boolean defValue) throws RemoteException { | ||
26 | Log.d(TAG, "getBoolean() key = " + key + ", defValue = " + defValue); | ||
27 | return defValue; | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public int getInt(String key, int defValue) throws RemoteException { | ||
32 | Log.d(TAG, "getInt() key = " + key + ", defValue = " + defValue); | ||
33 | return defValue; | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public String getString(String key, String defValue) throws RemoteException { | ||
38 | String value = defValue; | ||
39 | if (TextUtils.isEmpty(key)) { | ||
40 | return value; | ||
41 | } | ||
42 | |||
43 | switch (key.toLowerCase()) { | ||
44 | case "service/serviceinfo/iptvauthurl": | ||
45 | value = mConfig.getAuthAddress(); | ||
46 | break; | ||
47 | case "service/serviceinfo/iptvaccount": | ||
48 | case "service/serviceinfo/userid": | ||
49 | value = mConfig.getBusinessUserId(); | ||
50 | break; | ||
51 | case "service/serviceinfo/iptvpassword": | ||
52 | value = mConfig.getBusinessPasswd(); | ||
53 | break; | ||
54 | case "service/serviceinfo/stbid": | ||
55 | value = mConfig.getStbID(); | ||
56 | break; | ||
57 | case "service/serviceinfo/usertoken": | ||
58 | value = mConfig.getValue("usertoken"); | ||
59 | break; | ||
60 | case "service/serviceinfo/epgdomain": | ||
61 | case "service/serviceinfo/epginfo": | ||
62 | value = mConfig.getValue("epgdomain"); | ||
63 | break; | ||
64 | case "service/serviceinfo/epggroupnmb": | ||
65 | value = mConfig.getEPGGroupNMB(); | ||
66 | break; | ||
67 | case "service/serviceinfo/usergroupnmb": | ||
68 | value = mConfig.getUserGroupNMB(); | ||
69 | break; | ||
70 | case "service/serviceinfo/productmodel": | ||
71 | case "service/serviceinfo/terminaltype": | ||
72 | value = IptvConfig.getStbType(); | ||
73 | break; | ||
74 | case "service/serviceinfo/areaid": | ||
75 | value = mConfig.getValue("areaid"); | ||
76 | break; | ||
77 | case "service/serviceinfo/countyid": | ||
78 | value = mConfig.getValue("countyid"); | ||
79 | break; | ||
80 | case "service/serviceinfo/romversion": | ||
81 | case "service/serviceinfo/terminalversion": | ||
82 | value = IptvConfig.getSoftVersion(); | ||
83 | break; | ||
84 | case "service/serviceinfo/platforminfo": | ||
85 | value = getPlatform(); | ||
86 | break; | ||
87 | case "service/serviceinfo/manufacturerinfo": | ||
88 | value = "Fiberhome"; | ||
89 | break; | ||
90 | case "service/serviceinfo/mac": | ||
91 | value = mConfig.getMac(); | ||
92 | break; | ||
93 | case "service/serviceinfo/livechannels": | ||
94 | value = mConfig.getValue("livechannels"); | ||
95 | break; | ||
96 | case "service/serviceinfo/stbhdflag": | ||
97 | value = "HD"; | ||
98 | break; | ||
99 | case "service/serviceinfo/adshowstatus": | ||
100 | value = getADShowStatus(); | ||
101 | break; | ||
102 | case "service/serviceinfo/iptvstate": | ||
103 | value = mConfig.getIPTVState(); | ||
104 | break; | ||
105 | case "service/serviceinfo/ottcp": | ||
106 | value = mConfig.getOttCp(); | ||
107 | break; | ||
108 | default: | ||
109 | Log.e(TAG, "getString() unknown key = " + key); | ||
110 | break; | ||
111 | } | ||
112 | |||
113 | Log.d(TAG, "getString() key = " + key + ", value = " + value); | ||
114 | return value; | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | public boolean putBoolean(String key, boolean value) throws RemoteException { | ||
119 | Log.d(TAG, "putBoolean() key = " + key + ", value = " + value); | ||
120 | return false; | ||
121 | } | ||
122 | |||
123 | @Override | ||
124 | public boolean putInt(String key, int value) throws RemoteException { | ||
125 | Log.d(TAG, "putInt() key = " + key + ", value = " + value); | ||
126 | return false; | ||
127 | } | ||
128 | |||
129 | @Override | ||
130 | public boolean putString(String key, String value) throws RemoteException { | ||
131 | Log.d(TAG, "putString() key = " + key + ", value = " + value); | ||
132 | return false; | ||
133 | } | ||
134 | }; | ||
135 | } | ||
136 | |||
137 | private String getADShowStatus() { | ||
138 | boolean logoStatus = false; | ||
139 | boolean anmiStatus = false; | ||
140 | boolean authStatus = false; | ||
141 | |||
142 | try { | ||
143 | JSONObject jsonData = new JSONObject(); | ||
144 | JSONArray arrayName = new JSONArray(); | ||
145 | JSONArray arrayValue = new JSONArray(); | ||
146 | |||
147 | arrayName.put("logo"); | ||
148 | arrayValue.put(logoStatus ? "1" : "2"); | ||
149 | |||
150 | arrayName.put("anmi"); | ||
151 | arrayValue.put(anmiStatus ? "1" : "2"); | ||
152 | |||
153 | arrayName.put("auth"); | ||
154 | arrayValue.put(authStatus ? "1" : "2"); | ||
155 | |||
156 | jsonData.put("adtype", arrayName); | ||
157 | jsonData.put("advalue", arrayValue); | ||
158 | |||
159 | String status = jsonData.toString(); | ||
160 | Log.d(TAG, "getADShowStatus() status = " + status); | ||
161 | return status; | ||
162 | } catch (JSONException e) { | ||
163 | Log.e(TAG, "getADShowStatus() failed to generate JSON", e); | ||
164 | return null; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | private String getPlatform() { | ||
169 | Log.d(TAG, "getPlatform() platform = " + TestConfig.platform); | ||
170 | return TestConfig.platform; | ||
171 | } | ||
172 | |||
173 | @Override | ||
174 | public IBinder onBind(Intent intent) { | ||
175 | Log.d(TAG, "service on bind"); | ||
176 | return mBinder; | ||
177 | } | ||
178 | |||
179 | @Override | ||
180 | public void onCreate() { | ||
181 | super.onCreate(); | ||
182 | Log.d(TAG, "onCreate"); | ||
183 | mConfig = IptvConfig.getInstance(this); | ||
184 | } | ||
185 | |||
186 | @Override | ||
187 | public void onDestroy() { | ||
188 | super.onDestroy(); | ||
189 | Log.d(TAG, "onDestroy"); | ||
190 | } | ||
191 | |||
192 | @Override | ||
193 | public void onRebind(Intent intent) { | ||
194 | Log.d(TAG, "service on rebind"); | ||
195 | super.onRebind(intent); | ||
196 | } | ||
197 | |||
198 | @Override | ||
199 | public void onStart(Intent intent, int startId) { | ||
200 | Log.d(TAG, "service start id=" + startId); | ||
201 | } | ||
202 | |||
203 | @Override | ||
204 | public boolean onUnbind(Intent intent) { | ||
205 | Log.d(TAG, "service on unbind"); | ||
206 | return super.onUnbind(intent); | ||
207 | } | ||
208 | } |
1 | package com.topdraw.iptvlaunchertest; | ||
2 | |||
3 | import android.content.Context; | ||
4 | import android.util.Log; | ||
5 | import com.topdraw.iptvlaunchertest.common.JsonReader; | ||
6 | import org.json.JSONArray; | ||
7 | import org.json.JSONObject; | ||
8 | import java.util.HashMap; | ||
9 | import java.util.Iterator; | ||
10 | import java.util.Map; | ||
11 | |||
12 | /** | ||
13 | * iptv 参数 | ||
14 | */ | ||
15 | public class IptvConfig { | ||
16 | private static final String TAG = IptvConfig.class.getSimpleName(); | ||
17 | private static final Map<String,String> iptvConfigMap = new HashMap<>(); | ||
18 | private static volatile IptvConfig instance = null; | ||
19 | |||
20 | public static final String IPTV_AUTH_URL = "iptvauthurl"; | ||
21 | public static final String IPTV_ACCOUNT = "iptvaccount"; | ||
22 | public static final String USER_ID = "userid"; | ||
23 | public static final String IPTV_PASSWORD = "iptvpassword"; | ||
24 | public static final String STB_ID = "stbid"; | ||
25 | public static final String USER_TOEKN = "usertoken"; | ||
26 | public static final String EPG_DOMAIN = "epgdomain"; | ||
27 | public static final String EPG_INFO = "epginfo"; | ||
28 | public static final String EPG_GROUP_NMB = "epggroupnmb"; | ||
29 | public static final String USER_GROUP_NMB = "usergroupnmb"; | ||
30 | public static final String PRODUCT_MODEL = "productmodel"; | ||
31 | public static final String TERMINAL_TYPE = "terminaltype"; | ||
32 | public static final String AREA_ID = "areaid"; | ||
33 | public static final String COUNTY_ID = "countyid"; | ||
34 | public static final String ROM_VERSION = "romversion"; | ||
35 | public static final String TERMINAL_VERSION = "terminalversion"; | ||
36 | public static final String MAC = "mac"; | ||
37 | public static final String IPTV_STATE = "iptvstate"; | ||
38 | public static final String OT_TCP = "ottcp"; | ||
39 | public static final String LIVE_CHANNELS = "LiveChannels"; | ||
40 | |||
41 | private IptvConfig(Context context){ | ||
42 | JSONObject param = JsonReader.readJsonFromAssets(context,"iptv_param.json"); | ||
43 | JSONArray channels = JsonReader.readJsonArrFromAssets(context,"livechannels.json"); | ||
44 | Log.d(TAG, "IptvConfig param:"+param.toString()); | ||
45 | Log.d(TAG, "IptvConfig channels:"+channels.toString()); | ||
46 | for (Iterator<String> it = param.keys(); it.hasNext(); ) { | ||
47 | String key = it.next(); | ||
48 | iptvConfigMap.put(key,param.optString(key,"")); | ||
49 | } | ||
50 | iptvConfigMap.put("LiveChannels",channels.toString()); | ||
51 | } | ||
52 | |||
53 | public static IptvConfig getInstance(Context context) { | ||
54 | if(instance == null){ | ||
55 | synchronized (IptvConfig.class){ | ||
56 | if(instance==null){ | ||
57 | instance = new IptvConfig(context); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | return instance; | ||
62 | } | ||
63 | |||
64 | public static String getStbType() { | ||
65 | return TestConfig.stbType; | ||
66 | } | ||
67 | |||
68 | public static String getSoftVersion() { | ||
69 | return "1"; | ||
70 | } | ||
71 | |||
72 | public String getAuthAddress() { | ||
73 | return iptvConfigMap.get(IPTV_AUTH_URL); | ||
74 | } | ||
75 | |||
76 | public String getBusinessUserId() { | ||
77 | return iptvConfigMap.get(IPTV_ACCOUNT); | ||
78 | } | ||
79 | |||
80 | public String getBusinessPasswd() { | ||
81 | return iptvConfigMap.get(IPTV_PASSWORD); | ||
82 | } | ||
83 | |||
84 | public String getStbID() { | ||
85 | return iptvConfigMap.get(STB_ID); | ||
86 | } | ||
87 | |||
88 | public String getValue(String key) { | ||
89 | return iptvConfigMap.get(key); | ||
90 | } | ||
91 | |||
92 | public String getEPGGroupNMB() { | ||
93 | return iptvConfigMap.get(EPG_GROUP_NMB); | ||
94 | } | ||
95 | |||
96 | public String getUserGroupNMB() { | ||
97 | return iptvConfigMap.get(USER_GROUP_NMB); | ||
98 | } | ||
99 | |||
100 | public String getMac() { | ||
101 | return iptvConfigMap.get(MAC); | ||
102 | } | ||
103 | |||
104 | public String getIPTVState() { | ||
105 | return iptvConfigMap.get(IPTV_STATE); | ||
106 | } | ||
107 | |||
108 | public String getOttCp() { | ||
109 | return iptvConfigMap.get(OT_TCP); | ||
110 | } | ||
111 | } |
1 | package com.topdraw.iptvlaunchertest; | 1 | package com.topdraw.iptvlaunchertest; |
2 | 2 | ||
3 | import android.Manifest; | 3 | import android.Manifest; |
4 | import android.content.Intent; | ||
4 | import android.os.Build; | 5 | import android.os.Build; |
5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
6 | import android.webkit.WebSettings; | 7 | import android.webkit.WebSettings; |
... | @@ -12,6 +13,9 @@ import androidx.core.graphics.Insets; | ... | @@ -12,6 +13,9 @@ import androidx.core.graphics.Insets; |
12 | import androidx.core.view.ViewCompat; | 13 | import androidx.core.view.ViewCompat; |
13 | import androidx.core.view.WindowInsetsCompat; | 14 | import androidx.core.view.WindowInsetsCompat; |
14 | 15 | ||
16 | import com.android.smart.terminal.iptv.aidl.ServiceCfg; | ||
17 | import com.topdraw.iptvlaunchertest.common.Authentication; | ||
18 | |||
15 | public class MainActivity extends AppCompatActivity { | 19 | public class MainActivity extends AppCompatActivity { |
16 | private WebView webView; | 20 | private WebView webView; |
17 | 21 | ||
... | @@ -23,6 +27,7 @@ public class MainActivity extends AppCompatActivity { | ... | @@ -23,6 +27,7 @@ public class MainActivity extends AppCompatActivity { |
23 | @Override | 27 | @Override |
24 | protected void onCreate(Bundle savedInstanceState) { | 28 | protected void onCreate(Bundle savedInstanceState) { |
25 | super.onCreate(savedInstanceState); | 29 | super.onCreate(savedInstanceState); |
30 | startService(new Intent(this, ServiceCfg.class)); | ||
26 | EdgeToEdge.enable(this); | 31 | EdgeToEdge.enable(this); |
27 | setContentView(R.layout.activity_main); | 32 | setContentView(R.layout.activity_main); |
28 | ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { | 33 | ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { |
... | @@ -32,10 +37,10 @@ public class MainActivity extends AppCompatActivity { | ... | @@ -32,10 +37,10 @@ public class MainActivity extends AppCompatActivity { |
32 | }); | 37 | }); |
33 | webView = findViewById(R.id.webview); | 38 | webView = findViewById(R.id.webview); |
34 | initWeb(); | 39 | initWeb(); |
35 | initObject(); | ||
36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | 40 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
37 | requestPermissions(permissions,0); | 41 | requestPermissions(permissions,0); |
38 | } | 42 | } |
43 | initObject(); | ||
39 | webView.loadUrl(TestConfig.homeUrl); | 44 | webView.loadUrl(TestConfig.homeUrl); |
40 | } | 45 | } |
41 | 46 | ||
... | @@ -51,6 +56,7 @@ public class MainActivity extends AppCompatActivity { | ... | @@ -51,6 +56,7 @@ public class MainActivity extends AppCompatActivity { |
51 | 56 | ||
52 | //注册接口 | 57 | //注册接口 |
53 | private void initObject(){ | 58 | private void initObject(){ |
59 | webView.addJavascriptInterface(new Authentication(MainActivity.this),"Authentication"); | ||
54 | if(TestConfig.testDist==TestConfig.Skyworth){ | 60 | if(TestConfig.testDist==TestConfig.Skyworth){ |
55 | webView.addJavascriptInterface(new com.topdraw.iptvlaunchertest.sky.STBAppManager(this),"STBAppManager"); | 61 | webView.addJavascriptInterface(new com.topdraw.iptvlaunchertest.sky.STBAppManager(this),"STBAppManager"); |
56 | }else if(TestConfig.testDist==TestConfig.FiberHome){ | 62 | }else if(TestConfig.testDist==TestConfig.FiberHome){ | ... | ... |
... | @@ -9,6 +9,11 @@ public class TestConfig { | ... | @@ -9,6 +9,11 @@ public class TestConfig { |
9 | //测试目标盒子 | 9 | //测试目标盒子 |
10 | public static int testDist = FiberHome; | 10 | public static int testDist = FiberHome; |
11 | 11 | ||
12 | //测试平台 | ||
13 | public static final String platform = "HUAWEI";//"ZTE" | ||
14 | //设备名称 | ||
15 | public static final String stbType = "IPTV-TEST"; | ||
16 | |||
12 | //启动页地址 | 17 | //启动页地址 |
13 | public static final String homeUrl = "http://139.196.145.150:8060/JsAppLaunch/JsAppStartUp.html"; | 18 | public static final String homeUrl = "http://172.23.51.26:8070/AppEngine/apps/startApp/jsview.html"; |
14 | } | 19 | } | ... | ... |
1 | package com.topdraw.iptvlaunchertest.common; | ||
2 | |||
3 | import android.content.Context; | ||
4 | import android.webkit.JavascriptInterface; | ||
5 | |||
6 | import com.topdraw.iptvlaunchertest.IptvConfig; | ||
7 | import java.util.HashMap; | ||
8 | |||
9 | public class Authentication { | ||
10 | private static final HashMap<String,String> valueMap = new HashMap<>(); | ||
11 | public static final String UserID = "UserID"; | ||
12 | public static final String STBType = "STBType"; | ||
13 | public static final String STBVersion = "STBVersion"; | ||
14 | public static final String STBID = "STBID"; | ||
15 | public static final String EPGDomain = "EPGDomain"; | ||
16 | public static final String UserToken = "UserToken"; | ||
17 | public static final String SessionID = "SessionID"; | ||
18 | |||
19 | |||
20 | public Authentication(Context context) { | ||
21 | valueMap.put(UserID,IptvConfig.getInstance(context).getValue(IptvConfig.USER_ID)); | ||
22 | valueMap.put(STBType, IptvConfig.getStbType()); | ||
23 | valueMap.put(STBVersion, IptvConfig.getSoftVersion()); | ||
24 | valueMap.put(STBID, IptvConfig.getInstance(context).getStbID()); | ||
25 | valueMap.put(EPGDomain, IptvConfig.getInstance(context).getValue("epgdomain")); | ||
26 | valueMap.put(UserToken, IptvConfig.getInstance(context).getValue("usertoken")); | ||
27 | valueMap.put(SessionID, IptvConfig.getInstance(context).getValue("sessionid")); | ||
28 | } | ||
29 | |||
30 | @JavascriptInterface | ||
31 | public String CTCGetConfig(String encryToken){ | ||
32 | return valueMap.get(encryToken); | ||
33 | } | ||
34 | |||
35 | @JavascriptInterface | ||
36 | public String CTCSetConfig(String key,String value){ | ||
37 | return valueMap.put(key,value); | ||
38 | } | ||
39 | } |
1 | package com.topdraw.iptvlaunchertest.common; | ||
2 | |||
3 | import android.content.Context; | ||
4 | import android.content.res.AssetManager; | ||
5 | |||
6 | import org.json.JSONArray; | ||
7 | import org.json.JSONObject; | ||
8 | |||
9 | import java.io.BufferedReader; | ||
10 | import java.io.IOException; | ||
11 | import java.io.InputStream; | ||
12 | import java.io.InputStreamReader; | ||
13 | |||
14 | public class JsonReader { | ||
15 | |||
16 | public static JSONObject readJsonFromAssets(Context context, String jsonFileName) { | ||
17 | AssetManager assetManager = context.getAssets(); | ||
18 | JSONObject jsonObject = null; | ||
19 | |||
20 | try (InputStream inputStream = assetManager.open(jsonFileName); | ||
21 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { | ||
22 | |||
23 | StringBuilder stringBuilder = new StringBuilder(); | ||
24 | String line; | ||
25 | while ((line = reader.readLine()) != null) { | ||
26 | stringBuilder.append(line); | ||
27 | } | ||
28 | |||
29 | // 将 JSON 字符串转换为 JSONObject | ||
30 | jsonObject = new JSONObject(stringBuilder.toString()); | ||
31 | |||
32 | } catch (IOException | org.json.JSONException e) { | ||
33 | e.printStackTrace(); | ||
34 | } | ||
35 | |||
36 | return jsonObject; | ||
37 | } | ||
38 | |||
39 | public static JSONArray readJsonArrFromAssets(Context context, String jsonFileName) { | ||
40 | AssetManager assetManager = context.getAssets(); | ||
41 | JSONArray jsonArray = null; | ||
42 | |||
43 | try (InputStream inputStream = assetManager.open(jsonFileName); | ||
44 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { | ||
45 | |||
46 | StringBuilder stringBuilder = new StringBuilder(); | ||
47 | String line; | ||
48 | while ((line = reader.readLine()) != null) { | ||
49 | stringBuilder.append(line); | ||
50 | } | ||
51 | |||
52 | // 将 JSON 字符串转换为 JSONObject | ||
53 | jsonArray = new JSONArray(stringBuilder.toString()); | ||
54 | |||
55 | } catch (IOException | org.json.JSONException e) { | ||
56 | e.printStackTrace(); | ||
57 | } | ||
58 | |||
59 | return jsonArray; | ||
60 | } | ||
61 | } |
-
Please register or sign in to post a comment