Skip to content

Commit

Permalink
Target android14 (#74)
Browse files Browse the repository at this point in the history
* targetSdk 34
* Declare DfuService foreground type
* onPause/Resume don't signal back/forground
* Fix call to LayoutInflater; add StrictMode logging
* Fix screen update after DFU error
  • Loading branch information
martinwork authored Jul 24, 2024
1 parent 8626caa commit baac741
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
defaultConfig {
applicationId "com.samsung.microbit"
minSdkVersion 21
targetSdk 33
targetSdk 34
// When target SDK version is 30+,
// requestLegacyExternalStorage will continue to work for 29 Android 10
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>
Expand Down Expand Up @@ -167,7 +168,9 @@

<service
android:name=".service.DfuService"
android:enabled="true"/>
android:foregroundServiceType="connectedDevice"
android:enabled="true"
android:exported="false"/>

<service
android:name=".service.PluginService"
Expand All @@ -189,7 +192,7 @@
android:name=".service.PartialFlashingService"
android:enabled="true"
android:launchMode="singleInstance"
/>
android:exported="false"/>

<activity
android:name=".ui.activity.SplashScreenActivity"
Expand Down
35 changes: 33 additions & 2 deletions app/src/main/java/com/samsung/microbit/MBApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import android.app.Application;
import android.graphics.Typeface;
import android.os.Build;
import android.os.StrictMode;
import android.os.strictmode.Violation;
import android.util.Log;

import androidx.annotation.NonNull;
Expand All @@ -13,6 +16,8 @@

import com.samsung.microbit.MBAppState;

import java.util.concurrent.Executors;

/**
* Represents a custom class of the app.
* Provides some resources that use along app modules,
Expand All @@ -39,6 +44,30 @@ public void logi(String message) {

@Override
public void onCreate() {
// if (DEBUG) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
// .detectAll()
// .permitDiskReads()
// .penaltyLog()
// .penaltyListener(Executors.newSingleThreadExecutor(), new StrictMode.OnThreadViolationListener() {
// @Override
// public void onThreadViolation(Violation v) {
// }
// })
// .build());
//
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
// .detectAll()
// .penaltyLog()
// .penaltyListener(Executors.newSingleThreadExecutor(), new StrictMode.OnVmViolationListener() {
// @Override
// public void onVmViolation(Violation v) {
// }
// })
// .build());
// }
// }
super.onCreate();
app = this;
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
Expand Down Expand Up @@ -96,16 +125,18 @@ public void onStart(@NonNull LifecycleOwner owner) {
MBApp.getAppState().eventPairForeground();
}

//onPause & onResume occur when pairing confirmation dialogue shows

@Override
public void onResume(@NonNull LifecycleOwner owner) {
logi("onResume");
MBApp.getAppState().eventPairForeground();
//MBApp.getAppState().eventPairForeground();
}

@Override
public void onPause(@NonNull LifecycleOwner owner) {
logi("onPause");
MBApp.getAppState().eventPairBackground();
//MBApp.getAppState().eventPairBackground();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,8 @@ public void onClick(View v) {
final int errorType = intent.getIntExtra(DfuBaseService.EXTRA_ERROR_TYPE, 0);
String error_message = "";

PopUp.hide();

switch (errorType) {
case DfuBaseService.ERROR_TYPE_COMMUNICATION_STATE:
if ( errorCode == 0x0085) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

Project project = mProjects.get(position);
if(convertView == null) {
LayoutInflater inflater = LayoutInflater.from(MBApp.getApp());
LayoutInflater inflater = LayoutInflater.from( mProjectActivity);
convertView = inflater.inflate(R.layout.project_items, null);
}

Expand Down
2 changes: 1 addition & 1 deletion pfLibrary

0 comments on commit baac741

Please sign in to comment.