Skip to content

Commit

Permalink
Merge branch 'edge'
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed Dec 4, 2020
2 parents 0ff92da + c04e82e commit 12f55b2
Show file tree
Hide file tree
Showing 35 changed files with 339 additions and 117 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ proguard_logs/
.gradle/*
/build/
local.properties
*Thumbs.db
*Thumbs.db
app/google/release
13 changes: 10 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ android {
defaultConfig {
applicationId "github.daneren2005.dsub"
minSdkVersion 15
targetSdkVersion 26
versionCode 203
versionName '5.5.0'
targetSdkVersion 29
versionCode 206
versionName '5.5.2'
setProperty("archivesBaseName", "DSub $versionName")
resConfigs "de", "es", "fr", "hu", "nl", "pt-rPT", "ru", "sv"
vectorDrawables.useSupportLibrary = true
resValue 'string', 'account_type.subsonic', applicationId + ".subsonic"
resValue 'string', 'provider.search', applicationId + ".provider.DSubSearchProvider"
resValue 'string', 'provider.playlist', applicationId + ".playlists.provider"
resValue 'string', 'provider.podcast', applicationId + ".podcasts.provider"
resValue 'string', 'provider.starred', applicationId + ".starred.provider"
resValue 'string', 'provider.recently_added', applicationId + ".mostrecent.provider"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import github.daneren2005.serverproxy.ServerProxy;
import github.daneren2005.serverproxy.WebProxy;

import static github.daneren2005.dsub.util.compat.GoogleCompat.castApplicationId;

/**
* Created by owner on 2/9/14.
*/
Expand Down Expand Up @@ -421,14 +423,14 @@ public void onConnectionSuspended(int cause) {

void launchApplication() {
try {
Cast.CastApi.launchApplication(apiClient, EnvironmentVariables.CAST_APPLICATION_ID, false).setResultCallback(resultCallback);
Cast.CastApi.launchApplication(apiClient, castApplicationId(), false).setResultCallback(resultCallback);
} catch (Exception e) {
Log.e(TAG, "Failed to launch application", e);
}
}
void reconnectApplication() {
try {
Cast.CastApi.joinApplication(apiClient, EnvironmentVariables.CAST_APPLICATION_ID, sessionId).setResultCallback(resultCallback);
Cast.CastApi.joinApplication(apiClient, castApplicationId(), sessionId).setResultCallback(resultCallback);
} catch (Exception e) {
Log.e(TAG, "Failed to reconnect application", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.security.ProviderInstaller;
import static com.google.android.gms.cast.CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;

import github.daneren2005.dsub.service.ChromeCastController;
import github.daneren2005.dsub.service.DownloadService;
Expand All @@ -32,10 +33,17 @@ public static void installProvider(Context context) throws Exception{
ProviderInstaller.installIfNeeded(context);
}

public static String castApplicationId() {
if (EnvironmentVariables.CAST_APPLICATION_ID != null) {
return EnvironmentVariables.CAST_APPLICATION_ID;
} else {
return DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
}
}

public static boolean castAvailable() {
if (EnvironmentVariables.CAST_APPLICATION_ID == null) {
Log.w(TAG, "CAST_APPLICATION_ID not provided");
return false;
if (castApplicationId() == DEFAULT_MEDIA_RECEIVER_APPLICATION_ID) {
Log.i(TAG, "Using DEFAULT_MEDIA_RECEIVER_APPLICATION_ID for casting");
}
try {
Class.forName("com.google.android.gms.cast.CastDevice");
Expand All @@ -56,6 +64,6 @@ public static RemoteController getController(DownloadService downloadService, Me
}

public static String getCastControlCategory() {
return CastMediaControlIntent.categoryForCast(EnvironmentVariables.CAST_APPLICATION_ID);
return CastMediaControlIntent.categoryForCast(castApplicationId());
}
}
24 changes: 13 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
Expand All @@ -39,7 +39,8 @@
android:backupAgent="github.daneren2005.dsub.util.SettingsBackupAgent"
android:icon="@drawable/launch"
android:theme="@style/Theme.DSub.Light"
android:largeHeap="true">
android:largeHeap="true"
android:usesCleartextTraffic="true">

<uses-library android:name="android.test.runner" />

Expand Down Expand Up @@ -89,10 +90,11 @@
</intent-filter>
</activity>

<service android:name=".service.DownloadService"
android:label="DSub Playback Service"/>
<service android:name="github.daneren2005.dsub.service.DownloadService"
android:label="DSub Playback Service"
android:foregroundServiceType="location"/>

<service android:name=".service.AutoMediaBrowserService"
<service android:name="github.daneren2005.dsub.service.AutoMediaBrowserService"
android:exported="true">

<intent-filter>
Expand Down Expand Up @@ -214,24 +216,24 @@
</receiver>

<provider android:name="github.daneren2005.dsub.provider.DSubSearchProvider"
android:authorities="github.daneren2005.dsub.provider.DSubSearchProvider"/>
android:authorities="@string/provider.search"/>
<provider android:name="github.daneren2005.dsub.provider.PlaylistStubProvider"
android:authorities="github.daneren2005.dsub.playlists.provider"
android:authorities="@string/provider.playlist"
android:label="@string/button_bar.playlists"
android:exported="false"
android:syncable="true"/>
<provider android:name="github.daneren2005.dsub.provider.PodcastStubProvider"
android:authorities="github.daneren2005.dsub.podcasts.provider"
android:authorities="@string/provider.podcast"
android:label="@string/button_bar.podcasts"
android:exported="false"
android:syncable="true"/>
<provider android:name="github.daneren2005.dsub.provider.StarredStubProvider"
android:authorities="github.daneren2005.dsub.starred.provider"
android:authorities="@string/provider.starred"
android:label="@string/main.albums_starred"
android:exported="false"
android:syncable="true"/>
<provider android:name="github.daneren2005.dsub.provider.MostRecentStubProvider"
android:authorities="github.daneren2005.dsub.mostrecent.provider"
android:authorities="@string/provider.recently_added"
android:label="@string/main.albums_newest"
android:exported="false"
android:syncable="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package github.daneren2005.dsub.activity;

import android.Manifest;
import android.app.UiModeManager;
import android.content.Context;
import android.content.DialogInterface;
Expand Down Expand Up @@ -184,6 +185,17 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{ permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
}

SharedPreferences prefs = Util.getPreferences(this);
int instance = prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
String expectedSSID = prefs.getString(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance, "");
if(!expectedSSID.isEmpty()) {
String currentSSID = Util.getSSID(this);

if(currentSSID == "<unknown ssid>" && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, SubsonicActivity.PERMISSIONS_REQUEST_LOCATION);
}
}
}

@Override
Expand All @@ -198,6 +210,14 @@ public void onRequestPermissionsResult(int requestCode, String permissions[], in
finish();
}
}
case PERMISSIONS_REQUEST_LOCATION: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

} else {
Util.toast(this, R.string.permission_location_failed);
}
}
}
}

Expand Down Expand Up @@ -1248,7 +1268,7 @@ public void uncaughtException(Thread thread, Throwable throwable) {
PrintWriter printWriter = null;
try {

PackageInfo packageInfo = context.getPackageManager().getPackageInfo("github.daneren2005.dsub", 0);
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
file = new File(Environment.getExternalStorageDirectory(), "dsub-stacktrace.txt");
printWriter = new PrintWriter(file);
printWriter.println("Android API level: " + Build.VERSION.SDK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ else if(Constants.PREFERENCES_KEY_SYNC_MOST_RECENT.equals(key)) {
if(downloadService != null) {
MediaRouteManager mediaRouter = downloadService.getMediaRouter();

Boolean enabled = sharedPreferences.getBoolean(key, true);
Boolean enabled = sharedPreferences.getBoolean(key, false);
if (enabled) {
mediaRouter.addDLNAProvider();
} else {
Expand Down Expand Up @@ -528,6 +528,10 @@ protected void onAddEditTextToDialogView(View dialogView, final EditText editTex
super.onAddEditTextToDialogView(dialogView, editText);
ViewGroup root = (ViewGroup) ((ViewGroup) dialogView).getChildAt(0);

if(internalSSID == "<unknown ssid>" && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, SubsonicActivity.PERMISSIONS_REQUEST_LOCATION);
}

Button defaultButton = new Button(getContext());
defaultButton.setText(internalSSIDDisplay);
defaultButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -575,6 +579,12 @@ public void onClick(View v) {
serverSyncPreference.setSummary(R.string.settings_server_sync_summary);
serverSyncPreference.setTitle(R.string.settings_server_sync);

final CheckBoxPreference serverAuthHeaderPreference = new CheckBoxPreference(context);
serverAuthHeaderPreference.setKey(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance);
serverAuthHeaderPreference.setChecked(Util.isAuthHeaderEnabled(context, instance));
serverAuthHeaderPreference.setSummary(R.string.settings_server_authheaders_summary);
serverAuthHeaderPreference.setTitle(R.string.settings_server_authheaders);

final Preference serverOpenBrowser = new Preference(context);
serverOpenBrowser.setKey(Constants.PREFERENCES_KEY_OPEN_BROWSER);
serverOpenBrowser.setPersistent(false);
Expand Down Expand Up @@ -649,6 +659,7 @@ public boolean onPreferenceClick(Preference preference) {
screen.addPreference(serverPasswordPreference);
screen.addPreference(serverTagPreference);
screen.addPreference(serverSyncPreference);
screen.addPreference(serverAuthHeaderPreference);
screen.addPreference(serverTestConnectionPreference);
screen.addPreference(serverOpenBrowser);
screen.addPreference(serverRemoveServerPreference);
Expand Down Expand Up @@ -803,7 +814,7 @@ public boolean onPreferenceChange(Preference preference, Object value) {
try {
String url = (String) value;
new URL(url);
if (url.contains(" ") || url.contains("@")) {
if (url.contains(" ")) {
throw new Exception();
}
} catch (Exception x) {
Expand All @@ -824,7 +835,7 @@ public boolean onPreferenceChange(Preference preference, Object value) {
}

new URL(url);
if (url.contains(" ") || url.contains("@")) {
if (url.contains(" ")) {
throw new Exception();
}
} catch (Exception x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
lifecycleSupport.onStart(intent);
if(Build.VERSION.SDK_INT >= 26 && !this.isForeground()) {

String action = intent.getAction();
if(Build.VERSION.SDK_INT >= 26 && !this.isForeground() && !"KEYCODE_MEDIA_START".equals(action)) {
Notifications.shutGoogleUpNotification(this);
}
return START_NOT_STICKY;
Expand Down Expand Up @@ -1081,7 +1083,7 @@ public synchronized List<DownloadFile> getDownloads() {

public synchronized List<DownloadFile> getRecentDownloads() {
int from = Math.max(currentPlayingIndex - 10, 0);
int songsToKeep = Math.max(Util.getPreloadCount(this), 20);
int songsToKeep = Math.min(Math.max(Util.getPreloadCount(this), 20), downloadList.size());
int to = Math.min(currentPlayingIndex + songsToKeep, Math.max(downloadList.size() - 1, 0));
List<DownloadFile> temp = downloadList.subList(from, to);
temp.addAll(backgroundDownloadList);
Expand Down Expand Up @@ -1519,12 +1521,14 @@ public synchronized void setPlayerState(final PlayerState playerState) {
Util.requestAudioFocus(this, audioManager);
}

SharedPreferences prefs = Util.getPreferences(this);
boolean usingMediaStyleNotification = prefs.getBoolean(Constants.PREFERENCES_KEY_MEDIA_STYLE_NOTIFICATION, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;

if (show) {
Notifications.showPlayingNotification(this, this, handler, currentPlaying.getSong());
Notifications.showPlayingNotification(this, this, handler, currentPlaying.getSong(), usingMediaStyleNotification);
} else if (pause) {
SharedPreferences prefs = Util.getPreferences(this);
if(prefs.getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)) {
Notifications.showPlayingNotification(this, this, handler, currentPlaying.getSong());
if (prefs.getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)) {
Notifications.showPlayingNotification(this, this, handler, currentPlaying.getSong(), usingMediaStyleNotification);
} else {
Notifications.hidePlayingNotification(this, this, handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1911,11 +1911,16 @@ private HttpURLConnection getConnectionDirect(Context context, String url, Map<S

SharedPreferences prefs = Util.getPreferences(context);
int instance = getInstance(context);
String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
if (prefs.getBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + instance, false)) password = KeyStoreUtil.decrypt(password);
String encoded = Base64.encodeToString((username + ":" + password).getBytes("UTF-8"), Base64.NO_WRAP);;
connection.setRequestProperty("Authorization", "Basic " + encoded);
boolean authHeader = prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_AUTHHEADER + instance, true);
if(authHeader) {
String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null);
if (prefs.getBoolean(Constants.PREFERENCES_KEY_ENCRYPTED_PASSWORD + instance, false)) {
password = KeyStoreUtil.decrypt(password);
}
String encoded = Base64.encodeToString((username + ":" + password).getBytes("UTF-8"), Base64.NO_WRAP);
connection.setRequestProperty("Authorization", "Basic " + encoded);
}

// Force the connection to initiate
if(connection.getResponseCode() >= 500) {
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/github/daneren2005/dsub/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package github.daneren2005.dsub.util;

import github.daneren2005.dsub.BuildConfig;

/**
* @author Sindre Mehus
* @version $Id$
Expand Down Expand Up @@ -85,6 +87,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId";
public static final String PREFERENCES_KEY_USERNAME = "username";
public static final String PREFERENCES_KEY_PASSWORD = "password";
public static final String PREFERENCES_KEY_SERVER_AUTHHEADER = "authHeader";
public static final String PREFERENCES_KEY_ENCRYPTED_PASSWORD = "encryptedPassword";
public static final String PREFERENCES_KEY_INSTALL_TIME = "installTime";
public static final String PREFERENCES_KEY_THEME = "theme";
Expand Down Expand Up @@ -117,6 +120,7 @@ public final class Constants {
public static final String PREFERENCES_EQUALIZER_ON = "equalizerOn";
public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings";
public static final String PREFERENCES_KEY_PERSISTENT_NOTIFICATION = "persistentNotification";
public static final String PREFERENCES_KEY_MEDIA_STYLE_NOTIFICATION = "mediaStyleNotification";
public static final String PREFERENCES_KEY_GAPLESS_PLAYBACK = "gaplessPlayback";
public static final String PREFERENCES_KEY_REMOVE_PLAYED = "removePlayed";
public static final String PREFERENCES_KEY_KEEP_PLAYED_CNT = "keepPlayedCount";
Expand Down Expand Up @@ -212,17 +216,17 @@ public final class Constants {
public static final String FRAGMENT_POSITION = "fragmentPosition";

// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences";
public static final String OFFLINE_SYNC_NAME = "github.daneren2005.dsub.offline";
public static final String PREFERENCES_FILE_NAME = BuildConfig.APPLICATION_ID + "_preferences";
public static final String OFFLINE_SYNC_NAME = BuildConfig.APPLICATION_ID + ".offline";
public static final String OFFLINE_SYNC_DEFAULT = "syncDefaults";

// Account prefs
public static final String SYNC_ACCOUNT_NAME = "Subsonic Account";
public static final String SYNC_ACCOUNT_TYPE = "subsonic.org";
public static final String SYNC_ACCOUNT_PLAYLIST_AUTHORITY = "github.daneren2005.dsub.playlists.provider";
public static final String SYNC_ACCOUNT_PODCAST_AUTHORITY = "github.daneren2005.dsub.podcasts.provider";
public static final String SYNC_ACCOUNT_STARRED_AUTHORITY = "github.daneren2005.dsub.starred.provider";
public static final String SYNC_ACCOUNT_MOST_RECENT_AUTHORITY = "github.daneren2005.dsub.mostrecent.provider";
public static final String SYNC_ACCOUNT_TYPE = BuildConfig.APPLICATION_ID + ".subsonic";
public static final String SYNC_ACCOUNT_PLAYLIST_AUTHORITY = BuildConfig.APPLICATION_ID + ".playlists.provider";
public static final String SYNC_ACCOUNT_PODCAST_AUTHORITY = BuildConfig.APPLICATION_ID + ".podcasts.provider";
public static final String SYNC_ACCOUNT_STARRED_AUTHORITY = BuildConfig.APPLICATION_ID + ".starred.provider";
public static final String SYNC_ACCOUNT_MOST_RECENT_AUTHORITY = BuildConfig.APPLICATION_ID + ".mostrecent.provider";

public static final String TASKER_EXTRA_BUNDLE = "com.twofortyfouram.locale.intent.extra.BUNDLE";

Expand Down
Loading

0 comments on commit 12f55b2

Please sign in to comment.