1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-21 22:31:16 +02:00

Remove KitKat support

This commit is contained in:
Andreas Shimokawa 2022-09-09 19:58:34 +02:00 committed by Gitea
parent 2e6be6bea3
commit 969164ba5d
38 changed files with 75 additions and 184 deletions

View File

@ -42,16 +42,16 @@ def getGitHashShort = { ->
android {
compileOptions {
// for KitKat
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
// for Android 5+
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 29
buildToolsVersion "31.0.0"
defaultConfig {
applicationId "nodomain.freeyourgadget.gadgetbridge"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 29
multiDexEnabled true

View File

@ -125,7 +125,7 @@ public class GBApplication extends Application {
private static GBPrefs gbPrefs;
private static LockHandler lockHandler;
/**
* Note: is null on Lollipop and Kitkat
* Note: is null on Lollipop
*/
private static NotificationManager notificationManager;
@ -377,10 +377,6 @@ public class GBApplication extends Application {
dbLock.unlock();
}
public static boolean isRunningLollipopOrLater() {
return VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
public static boolean isRunningMarshmallowOrLater() {
return VERSION.SDK_INT >= Build.VERSION_CODES.M;
}

View File

@ -131,9 +131,7 @@ public class SleepAlarmWidget extends AppWidgetProvider {
alarms.add(alarm);
GBApplication.deviceService(deviceForWidget).onSetAlarms(alarms);
// if (GBApplication.isRunningLollipopOrLater()) {
// setAlarmViaAlarmManager(context, calendar.getTimeInMillis());
// }
// setAlarmViaAlarmManager(context, calendar.getTimeInMillis());
}
}
@ -145,7 +143,6 @@ public class SleepAlarmWidget extends AppWidgetProvider {
* @param triggerTime {@code long}: time at which the underlying alarm is triggered in wall time
* milliseconds since the epoch
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setAlarmViaAlarmManager(Context packageContext, long triggerTime) {
AlarmManager am = (AlarmManager) packageContext.getSystemService(Context.ALARM_SERVICE);
// TODO: launch the alarm configuration activity when clicking the alarm in the status bar

View File

@ -225,14 +225,12 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
return null;
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private ScanCallback getScanCallback() {
if (newBLEScanCallback != null) {
return newBLEScanCallback;
}
newBLEScanCallback = new ScanCallback() {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
@ -371,9 +369,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
if (oldBleScanning) {
stopOldBLEDiscovery();
} else {
if (GBApplication.isRunningLollipopOrLater()) {
stopBLEDiscovery();
}
stopBLEDiscovery();
}
} catch (Exception e) {
LOG.warn("Error stopping discovery", e);
@ -440,7 +436,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
if (what == Scanning.SCANNING_BT || what == Scanning.SCANNING_BT_NEXT_BLE) {
startBTDiscovery(what);
} else if (what == Scanning.SCANNING_BLE && GB.supportsBluetoothLE()) {
if (oldBleScanning || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
if (oldBleScanning) {
startOldBTLEDiscovery();
} else {
startBTLEDiscovery();
@ -462,7 +458,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
if (wasScanning == Scanning.SCANNING_BT || wasScanning == Scanning.SCANNING_BT_NEXT_BLE) {
stopBTDiscovery();
} else if (wasScanning == Scanning.SCANNING_BLE) {
if (oldBleScanning || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
if (oldBleScanning) {
stopOldBLEDiscovery();
} else {
stopBLEDiscovery();
@ -507,7 +503,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
/* New BTLE Discovery uses startScan (List<ScanFilter> filters,
ScanSettings settings,
ScanCallback callback) */
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private void startBTLEDiscovery() {
LOG.info("Starting BLE discovery");
@ -523,7 +518,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
setIsScanning(Scanning.SCANNING_BLE);
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private void stopBLEDiscovery() {
if (adapter == null) {
return;
@ -652,7 +646,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
return false;
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private ScanSettings getScanSettings() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return new ScanSettings.Builder()

View File

@ -187,20 +187,6 @@ public class DBHelper {
return false;
}
/**
* WITHOUT ROWID is only available with sqlite 3.8.2, which is available
* with Lollipop and later.
*
* @return the "WITHOUT ROWID" string or an empty string for pre-Lollipop devices
*/
@NonNull
public static String getWithoutRowId() {
if (GBApplication.isRunningLollipopOrLater()) {
return " WITHOUT ROWID;";
}
return "";
}
/**
* Looks up the user entity in the database. If a user exists already, it will
* be updated with the current preferences values. If no user exists yet, it will

View File

@ -141,7 +141,6 @@ public interface DeviceCoordinator {
* @return the list of scan filters, may be empty
*/
@NonNull
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
Collection<? extends ScanFilter> createBLEScanFilters();
GBDevice createDevice(GBDeviceCandidate candidate);

View File

@ -144,11 +144,7 @@ public class AppsManagementActivity extends AbstractGBActivity {
@Override
public void run() {
if (webView==null) return; // webView may have gone by the time we get called!
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(js, null);
} else {
webView.loadUrl("javascript: "+js);
}
webView.evaluateJavascript(js, null);
}
});
}

View File

@ -59,7 +59,6 @@ public class BangleJSCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
// TODO: filter on name beginning Bangle.js? Doesn't appear to be built-in :(
// https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder.html#setDeviceName(java.lang.String)

View File

@ -63,7 +63,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid hpService = new ParcelUuid(HPlusConstants.UUID_SERVICE_HP);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(hpService).build();

View File

@ -72,7 +72,6 @@ public abstract class HuamiCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid mi2Service = new ParcelUuid(MiBandService.UUID_SERVICE_MIBAND2_SERVICE);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(mi2Service).build();

View File

@ -45,7 +45,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class ID115Coordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid service = new ParcelUuid(ID115Constants.UUID_SERVICE_ID115);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(service).build();

View File

@ -58,7 +58,6 @@ public class ITagCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ScanFilter filter = new ScanFilter.Builder()
.setDeviceName("iTag")

View File

@ -55,7 +55,6 @@ public class TeclastH30Coordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid uuid = new ParcelUuid(JYouConstants.UUID_SERVICE_JYOU);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(uuid).build();

View File

@ -69,7 +69,6 @@ public class WatchXPlusDeviceCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid watchXpService = new ParcelUuid(WatchXPlusConstants.UUID_SERVICE_WATCHXPLUS);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(watchXpService).build();

View File

@ -62,7 +62,6 @@ public class MiBandCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid mi1Service = new ParcelUuid(MiBandService.UUID_SERVICE_MIBAND_SERVICE);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(mi1Service).build();

View File

@ -71,7 +71,6 @@ public class MiScale2DeviceCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid bodyCompositionService = new ParcelUuid(GattService.UUID_SERVICE_BODY_COMPOSITION);

View File

@ -47,7 +47,6 @@ public class No1F1Coordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid hpService = new ParcelUuid(No1F1Constants.UUID_SERVICE_NO1);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(hpService).build();

View File

@ -58,7 +58,6 @@ public class NutCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ScanFilter filter = new ScanFilter.Builder()
.setDeviceName("nut") // Nut Mini

View File

@ -70,7 +70,6 @@ public class QHybridCoordinator extends AbstractBLEDeviceCoordinator {
return DeviceType.UNKNOWN;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@NonNull
@Override
public Collection<? extends ScanFilter> createBLEScanFilters() {

View File

@ -34,7 +34,6 @@ public class SMAQ2OSSCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid service = new ParcelUuid(SMAQ2OSSConstants.UUID_SERVICE_SMAQ2OSS);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(service).build();

View File

@ -56,7 +56,6 @@ public class WaspOSCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
// TODO: filter on name beginning Bangle.js? Doesn't appear to be built-in :(
// https://developer.android.com/reference/android/bluetooth/le/ScanFilter.Builder.html#setDeviceName(java.lang.String)

View File

@ -49,7 +49,6 @@ public class Watch9DeviceCoordinator extends AbstractBLEDeviceCoordinator {
@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
ParcelUuid watch9Service = new ParcelUuid(Watch9Constants.UUID_SERVICE_WATCH9);
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(watch9Service).build();

View File

@ -186,15 +186,8 @@ public class NotificationListener extends NotificationListenerService {
}
for (StatusBarNotification sbn : sbns) {
if (sbn.getPostTime() == ts) {
if (GBApplication.isRunningLollipopOrLater()) {
String key = sbn.getKey();
NotificationListener.this.cancelNotification(key);
} else {
int id = sbn.getId();
String pkg = sbn.getPackageName();
String tag = sbn.getTag();
NotificationListener.this.cancelNotification(pkg, tag, id);
}
String key = sbn.getKey();
NotificationListener.this.cancelNotification(key);
}
}
break;
@ -284,7 +277,7 @@ public class NotificationListener extends NotificationListenerService {
if (handleMediaSessionNotification(sbn)) return;
int dndSuppressed = 0;
if (GBApplication.isRunningLollipopOrLater() && rankingMap != null) {
if (rankingMap != null) {
// Handle priority notifications for Do Not Disturb
Ranking ranking = new Ranking();
if (rankingMap.getRanking(sbn.getKey(), ranking)) {
@ -293,16 +286,14 @@ public class NotificationListener extends NotificationListenerService {
}
Prefs prefs = GBApplication.getPrefs();
if (GBApplication.isRunningLollipopOrLater()) {
if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {
return;
}
if (NotificationCompat.CATEGORY_CALL.equals(sbn.getNotification().category)
&& prefs.getBoolean("notification_support_voip_calls", false)
&& sbn.isOngoing()) {
handleCallNotification(sbn);
return;
}
if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {
return;
}
if (NotificationCompat.CATEGORY_CALL.equals(sbn.getNotification().category)
&& prefs.getBoolean("notification_support_voip_calls", false)
&& sbn.isOngoing()) {
handleCallNotification(sbn);
return;
}
if (shouldIgnoreNotification(sbn, false)) {
@ -735,15 +726,13 @@ public class NotificationListener extends NotificationListenerService {
if (handleMediaSessionNotification(sbn)) return;
if (GBApplication.isRunningLollipopOrLater()) {
if(Notification.CATEGORY_CALL.equals(sbn.getNotification().category)
&& activeCallPostTime == sbn.getPostTime()) {
activeCallPostTime = 0;
CallSpec callSpec = new CallSpec();
callSpec.command = CallSpec.CALL_END;
mLastCallCommand = callSpec.command;
GBApplication.deviceService().onSetCallState(callSpec);
}
if(Notification.CATEGORY_CALL.equals(sbn.getNotification().category)
&& activeCallPostTime == sbn.getPostTime()) {
activeCallPostTime = 0;
CallSpec callSpec = new CallSpec();
callSpec.command = CallSpec.CALL_END;
mLastCallCommand = callSpec.command;
GBApplication.deviceService().onSetCallState(callSpec);
}
if (shouldIgnoreNotification(sbn, true)) return;
@ -790,9 +779,7 @@ public class NotificationListener extends NotificationListenerService {
sbn.getPackageName()
);
if (GBApplication.isRunningLollipopOrLater()) {
infoMsg += ": " + sbn.getNotification().category;
}
infoMsg += ": " + sbn.getNotification().category;
LOG.debug(infoMsg);
}

View File

@ -452,12 +452,8 @@ public class GBDeviceService implements DeviceService {
* @return contact DisplayName, if found it
*/
private String getContactDisplayNameByNumber(String number) {
Uri uri;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(number));
} else {
uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
}
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(number));
String name = number;
if (number == null || number.equals("")) {

View File

@ -60,7 +60,6 @@ public class TransactionBuilder {
return add(action);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public TransactionBuilder requestMtu(int mtu){
return add(
new RequestMtuAction(mtu)

View File

@ -27,7 +27,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
public class RequestMtuAction extends BtLEAction {
private int mtu;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public RequestMtuAction(int mtu) {
super(null);
this.mtu = mtu;
@ -39,7 +38,6 @@ public class RequestMtuAction extends BtLEAction {
return true;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean run(BluetoothGatt gatt) {
return gatt.requestMtu(this.mtu);

View File

@ -2062,10 +2062,6 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
}
protected void requestMTU(int mtu) {
if (!GBApplication.isRunningLollipopOrLater()) {
LOG.warn("Requesting MTU is only supported in Lollipop or later");
return;
}
new TransactionBuilder("requestMtu")
.requestMtu(mtu)
.queue(getQueue());

View File

@ -140,9 +140,7 @@ class PebbleGATTClient extends BluetoothGattCallback {
subscribeToConnectionParams(gatt);
}
} else if (characteristic.getUuid().equals(MTU_CHARACTERISTIC)) {
if (GBApplication.isRunningLollipopOrLater()) {
gatt.requestMtu(339);
}
gatt.requestMtu(339);
}
}

View File

@ -56,7 +56,6 @@ public class GBWebClient extends WebViewClient {
};
private static final Logger LOG = LoggerFactory.getLogger(GBWebClient.class);
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
Uri parsedUri = request.getUrl();
@ -131,16 +130,12 @@ public class GBWebClient extends WebViewClient {
private WebResourceResponse mimicRawGitResponse(String path) {
if("/aHcVolle/TrekVolle/master/online.html".equals(path)) { //TrekVolle online check
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Map<String, String> headers = new HashMap<>();
headers.put("Access-Control-Allow-Origin", "*");
return new WebResourceResponse("text/html", "utf-8", 200, "OK",
headers,
new ByteArrayInputStream("1".getBytes())
);
} else {
return new WebResourceResponse("text/html", "utf-8", new ByteArrayInputStream("1".getBytes()));
}
Map<String, String> headers = new HashMap<>();
headers.put("Access-Control-Allow-Origin", "*");
return new WebResourceResponse("text/html", "utf-8", 200, "OK",
headers,
new ByteArrayInputStream("1".getBytes())
);
}
return null;
@ -190,14 +185,10 @@ public class GBWebClient extends WebViewClient {
Map<String, String> headers = new HashMap<>();
headers.put("Access-Control-Allow-Origin", "*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new WebResourceResponse("application/json", "utf-8", 200, "OK",
headers,
new ByteArrayInputStream(resp.toString().getBytes())
);
} else {
return new WebResourceResponse("application/json", "utf-8", new ByteArrayInputStream(resp.toString().getBytes()));
}
return new WebResourceResponse("application/json", "utf-8", 200, "OK",
headers,
new ByteArrayInputStream(resp.toString().getBytes())
);
} catch (JSONException e) {
LOG.warn("Error building the JSON weather message.", e);
}

View File

@ -739,11 +739,7 @@ public class QHybridSupport extends QHybridBaseSupport {
PendingIntent intent = PendingIntent.getActivity(getContext(), 0, emailIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
notificationBuilder.addAction(new Notification.Action(0, "report", intent));
}else{
notificationBuilder.addAction(0, "report", intent);
}
notificationBuilder.addAction(new Notification.Action(0, "report", intent));
GB.notify((int) System.currentTimeMillis(), notificationBuilder.build(), getContext());
}

View File

@ -148,9 +148,8 @@ public class FossilWatchAdapter extends WatchAdapter {
timeoutThread.start();
playPairingAnimation();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
queueWrite(new RequestMtuRequest(512), false);
}
queueWrite(new RequestMtuRequest(512), false);
getDeviceInfos();
}
@ -801,13 +800,11 @@ public class FossilWatchAdapter extends WatchAdapter {
log("dropping requetst " + request.getName());
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
new TransactionBuilder("requestMtu")
.requestMtu(512)
.queue(getDeviceSupport().getQueue());
new TransactionBuilder("requestMtu")
.requestMtu(512)
.queue(getDeviceSupport().getQueue());
this.fossilRequest = request;
}
this.fossilRequest = request;
}
private void log(String message) {

View File

@ -222,9 +222,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
saveRawActivityFiles = getDeviceSpecificPreferences().getBoolean("save_raw_activity_files", false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
queueWrite(new RequestMtuRequest(512));
}
queueWrite(new RequestMtuRequest(512));
listApplications();
getDeviceInfos();

View File

@ -24,7 +24,6 @@ public class RequestMtuRequest extends FossilRequest {
private int mtu;
private boolean finished = false;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public RequestMtuRequest(int mtu) {
this.mtu = mtu;
}

View File

@ -115,22 +115,21 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
private String getAudioPlayer(Context context) {
Prefs prefs = GBApplication.getPrefs();
String audioPlayer = prefs.getString("audio_player", "default");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
MediaSessionManager mediaSessionManager =
(MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
MediaSessionManager mediaSessionManager =
(MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
try {
List<MediaController> controllers = mediaSessionManager.getActiveSessions(
new ComponentName(context, NotificationListener.class));
try {
List<MediaController> controllers = mediaSessionManager.getActiveSessions(
new ComponentName(context, NotificationListener.class));
try {
MediaController controller = controllers.get(0);
audioPlayer = controller.getPackageName();
} catch (IndexOutOfBoundsException e) {
LOG.error("No media controller available", e);
}
} catch (SecurityException e) {
LOG.warn("No permission to get media sessions - did not grant notification access?", e);
MediaController controller = controllers.get(0);
audioPlayer = controller.getPackageName();
} catch (IndexOutOfBoundsException e) {
LOG.error("No media controller available", e);
}
} catch (SecurityException e) {
LOG.warn("No permission to get media sessions - did not grant notification access?", e);
}
return audioPlayer;
}
}

View File

@ -183,8 +183,7 @@ public class AndroidUtils {
String selection = null;
String[] selectionArgs = null;
// Uri is different in versions after KITKAT (Android 4.4), we need to
if (Build.VERSION.SDK_INT >= 19 && DocumentsContract.isDocumentUri(context.getApplicationContext(), uri)) {
if (DocumentsContract.isDocumentUri(context.getApplicationContext(), uri)) {
if ("com.android.externalstorage.documents".equals(uri.getAuthority())) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");

View File

@ -265,16 +265,7 @@ public class FileUtils {
}
if (!GBEnvironment.env().isLocalTest()) { // don't do this with robolectric
final String storageState;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
storageState = Environment.getExternalStorageState(dir);
} else if(i == 0) {
// the first directory is also the primary external storage, i.e. the same as Environment.getExternalFilesDir()
storageState = Environment.getExternalStorageState();
} else {
// Assume it is mounted on older android versions - we test writing later
storageState = Environment.MEDIA_MOUNTED;
}
final String storageState = Environment.getExternalStorageState(dir);
if (!Environment.MEDIA_MOUNTED.equals(storageState)) {
GB.log("ignoring '" + storageState + "' external storage dir: " + dir, GB.INFO, null);
continue;

View File

@ -190,7 +190,7 @@ public class GB {
deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_DISCONNECT);
PendingIntent disconnectPendingIntent = PendingIntent.getService(context, 0, deviceCommunicationServiceIntent, PendingIntent.FLAG_ONE_SHOT);
builder.addAction(R.drawable.ic_notification_disconnected, context.getString(R.string.controlcenter_disconnect), disconnectPendingIntent);
if (GBApplication.isRunningLollipopOrLater() && DeviceHelper.getInstance().getCoordinator(device).supportsActivityDataFetching()) { //for some reason this fails on KK
if (DeviceHelper.getInstance().getCoordinator(device).supportsActivityDataFetching()) {
deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_FETCH_RECORDED_DATA);
deviceCommunicationServiceIntent.putExtra(EXTRA_RECORDED_DATA_TYPES, ActivityKind.TYPE_ACTIVITY);
PendingIntent fetchPendingIntent = PendingIntent.getService(context, 1, deviceCommunicationServiceIntent, PendingIntent.FLAG_ONE_SHOT);
@ -239,7 +239,7 @@ public class GB {
builder.setColor(context.getResources().getColor(R.color.accent));
}
if (GBApplication.isRunningLollipopOrLater() && anyDeviceSupportesActivityDataFetching) { //for some reason this fails on KK
if (anyDeviceSupportesActivityDataFetching) {
Intent deviceCommunicationServiceIntent = new Intent(context, DeviceCommunicationService.class);
deviceCommunicationServiceIntent.setAction(DeviceService.ACTION_FETCH_RECORDED_DATA);
deviceCommunicationServiceIntent.putExtra(EXTRA_RECORDED_DATA_TYPES, ActivityKind.TYPE_ACTIVITY);
@ -248,9 +248,8 @@ public class GB {
}
}
if (GBApplication.isRunningLollipopOrLater()) {
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
if (GBApplication.minimizeNotification()) {
builder.setPriority(Notification.PRIORITY_MIN);
}
@ -276,9 +275,9 @@ public class GB {
PendingIntent reconnectPendingIntent = PendingIntent.getService(context, 2, deviceCommunicationServiceIntent, PendingIntent.FLAG_ONE_SHOT);
builder.addAction(R.drawable.ic_notification, context.getString(R.string.controlcenter_connect), reconnectPendingIntent);
}
if (GBApplication.isRunningLollipopOrLater()) {
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
if (GBApplication.minimizeNotification()) {
builder.setPriority(Notification.PRIORITY_MIN);
}

View File

@ -138,14 +138,10 @@ public class WebViewSingleton {
Map<String, String> headers = new HashMap<>();
headers.put("Access-Control-Allow-Origin", "*");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
internetResponse = new WebResourceResponse(data.getString("content-type"), data.getString("content-encoding"), 200, "OK",
headers,
new ByteArrayInputStream(data.getString("response").getBytes(Charset.forName(getCharsetFromHeaders(data.getString("content-type")))))
);
} else {
internetResponse = new WebResourceResponse(data.getString("content-type"), data.getString("content-encoding"), new ByteArrayInputStream(data.getString("response").getBytes(Charset.forName(getCharsetFromHeaders(data.getString("content-type"))))));
}
internetResponse = new WebResourceResponse(data.getString("content-type"), data.getString("content-encoding"), 200, "OK",
headers,
new ByteArrayInputStream(data.getString("response").getBytes(Charset.forName(getCharsetFromHeaders(data.getString("content-type")))))
);
latch.countDown();
}