1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2024-12-27 01:13:31 +01:00

インストールIDとデバイストークンを保存する先をバックアップ対象外のファイルに変更した

This commit is contained in:
tateisu 2017-06-03 19:31:25 +09:00
parent 5821b5b906
commit f1b0b7a28a
12 changed files with 78 additions and 21 deletions

View File

@ -19,6 +19,7 @@
<w>reblogged</w>
<w>reblogs</w>
<w>sephiroth</w>
<w>sharedpref</w>
<w>simeji</w>
<w>styler</w>
<w>subwaytooter</w>

View File

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -9,8 +9,8 @@ android {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 25
versionCode 76
versionName "0.7.6"
versionCode 77
versionName "0.7.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -15,6 +15,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme.Light"
android:largeHeap="true"
android:fullBackupContent="@xml/backup_spec"
>
<receiver android:name=".AlarmReceiver">
<intent-filter>

View File

@ -320,8 +320,8 @@ public class ActAccountSetting extends AppCompatActivity
void unregister(){
try{
String install_id = App1.pref.getString( Pref.KEY_INSTALL_ID, null );
String install_id = PrefDevice.prefDevice( ActAccountSetting.this ).getString( PrefDevice.KEY_INSTALL_ID,null);
if( TextUtils.isEmpty( install_id ) ){
log.d( "performAccountRemove: missing install_id" );
return;

View File

@ -17,6 +17,8 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.text.TextUtils;
import com.google.firebase.iid.FirebaseInstanceId;
import org.hjson.JsonObject;
import org.hjson.JsonValue;
import org.json.JSONArray;
@ -138,10 +140,14 @@ public class AlarmService extends IntentService {
// 同期処理を行って良い
@Override protected void onHandleIntent( @Nullable Intent intent ){
bStreamListenerTest =false;
// クラッシュレポートによると App1.onCreate より前にここを通る場合がある
// データベースへアクセスできるようにする
App1.prepareDB( this.getApplicationContext() );
// インストールIDを生成する
// インストールID生成時にSavedAccountテーブルを操作することがあるので
// アカウントリストの取得より先に行う
install_id = getInstallId();
if( intent != null ){
@ -314,12 +320,33 @@ public class AlarmService extends IntentService {
}
String getInstallId(){
String sv = pref.getString(Pref.KEY_INSTALL_ID,null);
SharedPreferences prefDevice = PrefDevice.prefDevice( this );
String sv = prefDevice.getString(PrefDevice.KEY_INSTALL_ID,null);
if( ! TextUtils.isEmpty( sv ) ) return sv;
// インストールIDを生成する前に各データの通知登録キャッシュをクリアする
SavedAccount.clearRegistrationCache();
try{
String device_token = pref.getString( Pref.KEY_DEVICE_TOKEN, null );
if( TextUtils.isEmpty( device_token ) ) return null;
String device_token = prefDevice.getString( PrefDevice.KEY_DEVICE_TOKEN, null );
if( TextUtils.isEmpty( device_token ) ){
try{
// トークンがまだ生成されていない場合このメソッドは null を返します
device_token = FirebaseInstanceId.getInstance().getToken();
if( TextUtils.isEmpty( device_token ) ){
log.e("getInstallId: missing device token.");
return null;
}else{
prefDevice.edit().putString( PrefDevice.KEY_DEVICE_TOKEN, device_token ).apply();
}
}catch(Throwable ex2){
log.e("getInstallId: could not get device token.");
ex2.printStackTrace();
return null;
}
}
Request request = new Request.Builder()
.url( APP_SERVER + "/counter" )
@ -336,7 +363,7 @@ public class AlarmService extends IntentService {
//noinspection ConstantConditions
sv = Utils.digestSHA256( device_token + UUID.randomUUID() + response.body().string() );
pref.edit().putString(Pref.KEY_INSTALL_ID, sv).apply();
prefDevice.edit().putString(PrefDevice.KEY_INSTALL_ID, sv).apply();
return sv;
@ -346,11 +373,11 @@ public class AlarmService extends IntentService {
}
}
static final String REGISTER_KEY_UNREGISTERED = "unregistered";
private void unregisterDeviceToken( @NonNull SavedAccount account ){
try{
if( REGISTER_KEY_UNREGISTERED.equals( account.register_key ) ){
if( SavedAccount.REGISTER_KEY_UNREGISTERED.equals( account.register_key ) ){
log.d("unregisterDeviceToken: already unregistered.");
return;
}
@ -383,7 +410,7 @@ public class AlarmService extends IntentService {
log.e( "unregisterDeviceToken: %s", response );
if( response.isSuccessful() ){
account.register_key = REGISTER_KEY_UNREGISTERED;
account.register_key = SavedAccount.REGISTER_KEY_UNREGISTERED;
account.register_time = 0L;
account.saveRegisterKey();
}
@ -402,7 +429,9 @@ public class AlarmService extends IntentService {
return false;
}
String device_token = pref.getString( Pref.KEY_DEVICE_TOKEN, null );
SharedPreferences prefDevice = PrefDevice.prefDevice( this );
String device_token = prefDevice.getString( PrefDevice.KEY_DEVICE_TOKEN, null );
if( TextUtils.isEmpty( device_token ) ){
log.d("registerDeviceToken: missing device_token");
return false;
@ -413,8 +442,13 @@ public class AlarmService extends IntentService {
log.d("registerDeviceToken: missing access_token");
return false;
}
String tag = account.notification_tag;
if( SavedAccount.REGISTER_KEY_UNREGISTERED.equals( account.register_key ) ){
tag = null;
}
if( TextUtils.isEmpty( tag ) ){
tag = account.notification_tag = Utils.digestSHA256( install_id + account.db_id + account.acct );
account.saveNotificationTag();

View File

@ -338,8 +338,8 @@ public class AppDataExporter {
break;
// just ignore
case Pref.KEY_DEVICE_TOKEN:
case Pref.KEY_INSTALL_ID:
case "device_token":
case "install_id":
reader.skipValue();
e.remove( k );
break;

View File

@ -18,8 +18,7 @@ public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
String token = FirebaseInstanceId.getInstance().getToken();
log.d("onTokenRefresh: instance_token=%s",token);
Pref.pref(this).edit().putString(Pref.KEY_DEVICE_TOKEN,token).apply();
PrefDevice.prefDevice(this).edit().putString(PrefDevice.KEY_DEVICE_TOKEN,token).apply();
Intent intent = new Intent(this,AlarmService.class);
intent.setAction( AlarmService.ACTION_DEVICE_TOKEN );

View File

@ -48,8 +48,7 @@ public class Pref {
static final String KEY_MEDIA_THUMB_HEIGHT = "MediaThumbHeight";
static final String KEY_TIMELINE_FONT = "timeline_font";
static final String KEY_DONT_CROP_MEDIA_THUMBNAIL = "DontCropMediaThumb";
static final String KEY_DEVICE_TOKEN = "device_token";
static final String KEY_INSTALL_ID = "install_id";
static final String KEY_STREAM_LISTENER_SECRET = "stream_listener_secret";
static final String KEY_STREAM_LISTENER_CONFIG_URL = "stream_listener_config_url";

View File

@ -0,0 +1,16 @@
package jp.juggler.subwaytooter;
import android.content.Context;
import android.content.SharedPreferences;
public class PrefDevice {
private static String file_name = "device";
static SharedPreferences prefDevice( Context context ){
return context.getSharedPreferences( file_name, Context.MODE_PRIVATE );
}
static final String KEY_DEVICE_TOKEN = "device_token";
static final String KEY_INSTALL_ID = "install_id";
}

View File

@ -311,9 +311,12 @@ public class SavedAccount extends TootAccount implements LinkClickContext {
App1.getDB().update( table, cv, COL_ID + "=?", new String[]{ Long.toString( db_id ) } );
}
public static final String REGISTER_KEY_UNREGISTERED = "unregistered";
public static void clearRegistrationCache(){
ContentValues cv = new ContentValues();
cv.put( COL_REGISTER_KEY, REGISTER_KEY_UNREGISTERED );
cv.put( COL_REGISTER_TIME, 0L );
App1.getDB().update( table, cv, null, null);
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="sharedpref" path="device.xml"/>
</full-backup-content>