Skip to content

Commit 85a6d60

Browse files
committed
v2.01: adjusted to latest library and Android SDK changes
1 parent dc65c74 commit 85a6d60

File tree

12 files changed

+117
-108
lines changed

12 files changed

+117
-108
lines changed

app/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ android {
2828
storePassword 'aGVhZHdpbmRNYWlu'
2929
}
3030
}
31-
compileSdkVersion 28
31+
compileSdkVersion 34
3232
defaultConfig {
3333
applicationId "com.hmdm.pager"
3434
minSdkVersion 14
35-
targetSdkVersion 28
36-
versionCode 2
37-
versionName "1.02"
35+
targetSdkVersion 34
36+
versionCode 201
37+
versionName "2.01"
3838
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3939
}
4040
buildTypes {
@@ -47,6 +47,7 @@ android {
4747
signingConfig signingConfigs.config
4848
}
4949
}
50+
namespace 'com.hmdm.pager'
5051
}
5152

5253
dependencies {
@@ -67,5 +68,5 @@ dependencies {
6768
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
6869
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
6970

70-
implementation files('libs/hmdm-1.0.5.aar')
71+
implementation files('libs/hmdm-1.1.7.aar')
7172
}

app/libs/hmdm-1.0.5.aar

-28.9 KB
Binary file not shown.

app/libs/hmdm-1.1.7.aar

35.3 KB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
~ limitations under the License.
1919
-->
2020

21-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22-
package="com.hmdm.pager">
21+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2322

2423
<uses-permission android:name="android.permission.INTERNET"/>
2524
<uses-permission android:name="android.permission.WAKE_LOCK" android:required="false"/>
2625
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2726
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
27+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
28+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
29+
30+
<queries>
31+
<package android:name="com.hmdm.launcher" />
32+
</queries>
2833

2934
<application
3035
android:allowBackup="true"
@@ -37,15 +42,20 @@
3742
<activity
3843
android:name=".MainActivity"
3944
android:label="@string/app_name"
45+
android:exported="true"
4046
android:theme="@style/AppTheme.NoActionBar">
4147
<intent-filter>
4248
<action android:name="android.intent.action.MAIN" />
43-
4449
<category android:name="android.intent.category.LAUNCHER" />
50+
<category android:name="android.intent.category.DEFAULT" />
4551
</intent-filter>
4652
</activity>
4753

48-
<service android:name=".service.PagerService"/>
54+
<service android:name=".service.PagerService"
55+
android:foregroundServiceType="specialUse">
56+
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
57+
android:value="Pager service"/>
58+
</service>
4959

5060
<receiver
5161
android:name=".receiver.BootReceiver"
@@ -61,7 +71,10 @@
6171
</intent-filter>
6272
</receiver>
6373

64-
<receiver android:name=".receiver.StartActivityReceiver" android:enabled="true"/>
74+
<receiver
75+
android:name=".receiver.StartActivityReceiver"
76+
android:enabled="true"
77+
android:exported="false"/>
6578

6679
</application>
6780

app/src/main/java/com/hmdm/pager/Const.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ public class Const {
2323
public static final String LOG_TAG = "com.hmdm.Pager";
2424
public static final int CONNECTION_TIMEOUT = 10;
2525

26-
public static final String INTENT_PUSH_NOTIFICATION_TYPE = "com.hmdm.push.textMessage";
27-
public static final String INTENT_PUSH_NOTIFICATION_EXTRA = "com.hmdm.PUSH_DATA";
28-
29-
public static final String STATUS_OK = "OK";
26+
public static final String PUSH_MESSAGE_TYPE = "textMessage";
3027

3128
public static final int TASK_SUCCESS = 0;
3229
public static final int TASK_ERROR = 1;
33-
public static final int TASK_NETWORK_ERROR = 2;
34-
public static final int TASK_IDLE = 3;
3530

3631
public static final int HMDM_RECONNECT_DELAY_FIRST = 5000;
3732
public static final int HMDM_RECONNECT_DELAY_NEXT = 5000;

app/src/main/java/com/hmdm/pager/MainActivity.java

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
package com.hmdm.pager;
2121

22-
import android.content.BroadcastReceiver;
2322
import android.content.Context;
2423
import android.content.Intent;
25-
import android.content.IntentFilter;
2624
import android.os.AsyncTask;
2725
import android.os.Build;
2826
import android.os.Bundle;
@@ -37,12 +35,14 @@
3735

3836
import androidx.appcompat.app.AppCompatActivity;
3937
import androidx.appcompat.widget.Toolbar;
40-
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
4138
import androidx.recyclerview.widget.DividerItemDecoration;
4239
import androidx.recyclerview.widget.LinearLayoutManager;
4340
import androidx.recyclerview.widget.RecyclerView;
4441

42+
import com.hmdm.HeadwindMDM;
4543
import com.hmdm.MDMException;
44+
import com.hmdm.MDMPushHandler;
45+
import com.hmdm.MDMPushMessage;
4646
import com.hmdm.MDMService;
4747
import com.hmdm.pager.db.DatabaseHelper;
4848
import com.hmdm.pager.db.MessageTable;
@@ -55,27 +55,30 @@
5555
import java.util.Date;
5656
import java.util.List;
5757

58-
public class MainActivity extends AppCompatActivity implements MDMService.ResultHandler {
58+
public class MainActivity extends AppCompatActivity implements HeadwindMDM.EventHandler {
5959

6060
private SettingsHelper settings;
6161

62-
private MDMService mdmService;
62+
private HeadwindMDM headwindMDM;
6363
private boolean mdmConnected = false;
6464

6565
private TextView emptyTextView;
6666
private RecyclerView recyclerView;
6767
private MessageAdapter adapter;
6868
private RecyclerView.LayoutManager layoutManager;
69+
private Handler receiveHandler = new Handler();
6970

70-
private BroadcastReceiver newMessageReceiver = new BroadcastReceiver() {
71+
private MDMPushHandler mdmPushHandler = new MDMPushHandler() {
7172
@Override
72-
public void onReceive(Context context, Intent intent) {
73-
if (intent.getAction().equals(Const.ACTION_NEW_MESSAGE)) {
73+
public void onMessageReceived(MDMPushMessage mdmPushMessage) {
74+
// We need to save incoming message in the database by the service,
75+
// So we implement a delay here
76+
receiveHandler.postDelayed(() -> {
7477
adapter.updateMessages();
7578
adapter.notifyDataSetChanged();
7679
updateItemState();
7780
notifyMessagesRead();
78-
}
81+
}, 300);
7982
}
8083
};
8184

@@ -100,7 +103,7 @@ protected void onCreate(Bundle savedInstanceState) {
100103
recyclerView.addItemDecoration(dividerItemDecoration);
101104

102105
settings = SettingsHelper.getInstance(this);
103-
mdmService = MDMService.getInstance();
106+
headwindMDM = HeadwindMDM.getInstance();
104107

105108
Intent intent = new Intent(this, PagerService.class);
106109
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -141,27 +144,31 @@ protected void onNewIntent(Intent intent) {
141144
protected void onResume() {
142145
super.onResume();
143146

144-
if (mdmConnected) {
145-
queryMdm();
147+
String[] messageTypes = {Const.PUSH_MESSAGE_TYPE};
148+
mdmPushHandler.register(messageTypes, this);
149+
150+
if (!headwindMDM.isConnected()) {
151+
if (!headwindMDM.connect(this, this)) {
152+
// Your application is running outside Headwind MDM
153+
Toast.makeText(MainActivity.this, getString(R.string.mdm_connect_error), Toast.LENGTH_LONG).show();
154+
}
146155
} else {
147-
mdmService.connect(this, this);
156+
// Already connected, but settings may have changed
157+
// when our app was in the background, so reload them
158+
queryMdm();
148159
}
149160
updateItemState();
150161

151162
adapter.updateMessages();
152163
adapter.notifyDataSetChanged();
153164

154-
LocalBroadcastManager.getInstance(this).registerReceiver(newMessageReceiver,
155-
new IntentFilter(Const.ACTION_NEW_MESSAGE));
156-
157165
notifyMessagesRead();
158166
}
159167

160168
@Override
161169
protected void onPause() {
162170
super.onPause();
163-
164-
LocalBroadcastManager.getInstance(this).unregisterReceiver(newMessageReceiver);
171+
mdmPushHandler.unregister(this);
165172
}
166173

167174
private void updateItemState() {
@@ -217,31 +224,22 @@ private void queryMdm() {
217224
}
218225

219226
@Override
220-
public void onMDMConnected() {
221-
mdmConnected = true;
222-
MDMService.Log.i(Const.LOG_TAG, "activity connected to Headwind MDM");
223-
227+
public void onHeadwindMDMConnected() {
228+
// Connected to Headwind MDM, now you can load settings and use other MDM functions
229+
MDMService.Log.i(Const.LOG_TAG, "Activity connected to Headwind MDM");
224230
queryMdm();
225231
}
226232

227233
@Override
228-
public void onMDMDisconnected() {
229-
mdmConnected = false;
230-
231-
// Reconnect (this could be after crash of Headwind MDM!)
232-
MDMService.Log.i(Const.LOG_TAG, "activity disconnected from Headwind MDM");
233-
new Handler().postDelayed(new MDMReconnectRunnable(), Const.HMDM_RECONNECT_DELAY_FIRST);
234+
public void onHeadwindMDMDisconnected() {
235+
MDMService.Log.i(Const.LOG_TAG, "Activity disconnected from Headwind MDM");
234236
}
235237

236-
public class MDMReconnectRunnable implements Runnable {
237-
@Override
238-
public void run() {
239-
if (!mdmService.connect(MainActivity.this, MainActivity.this)) {
240-
// Retry in 1 minute
241-
MDMService.Log.i(Const.LOG_TAG, "Failed to connect to Headwind MDM, scheduling connection");
242-
new Handler().postDelayed(this, Const.HMDM_RECONNECT_DELAY_NEXT);
243-
}
244-
}
238+
@Override
239+
public void onHeadwindMDMConfigChanged() {
240+
// Settings were changed on the server, you need to reload them
241+
MDMService.Log.i(Const.LOG_TAG, "Reloading configuration from Headwind MDM");
242+
queryMdm();
245243
}
246244

247245
public static class MessageViewHolder extends RecyclerView.ViewHolder {

app/src/main/java/com/hmdm/pager/http/json/Message.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.hmdm.pager.http.json;
2121

22+
import android.annotation.SuppressLint;
2223
import android.database.Cursor;
2324

2425
import org.json.JSONException;
@@ -47,6 +48,7 @@ public Message() {
4748
initDefaults();
4849
}
4950

51+
@SuppressLint("Range")
5052
public Message(Cursor cursor) {
5153
setId(cursor.getInt(cursor.getColumnIndex("_id")));
5254
setTs(cursor.getLong(cursor.getColumnIndex("ts")));

0 commit comments

Comments
 (0)