Skip to content

Commit 0286b7c

Browse files
authored
Merge pull request #82 from NordicSemiconductor/bugfix/name
Bugs fixed
2 parents 7a6b977 + 58188f1 commit 0286b7c

File tree

8 files changed

+39
-45
lines changed

8 files changed

+39
-45
lines changed

log-timber/src/main/java/no/nordicsemi/android/log/timber/nRFLoggerTree.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public class nRFLoggerTree extends Timber.Tree {
5050
// Constructors
5151

5252
public nRFLoggerTree(final @NonNull Context context,
53-
final @NonNull String key, final @NonNull String name) {
53+
final @NonNull String key, final @Nullable String name) {
5454
this.session = Logger.newSession(context, null, key, name);
5555
}
5656

5757
public nRFLoggerTree(final @NonNull Context context,
5858
final @Nullable String profile,
59-
final @NonNull String key, final @NonNull String name) {
59+
final @NonNull String key, final @Nullable String name) {
6060
this.session = Logger.newSession(context, profile, key, name);
6161
}
6262

log/src/main/java/no/nordicsemi/android/log/ILogSession.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
package no.nordicsemi.android.log;
3333

34-
import android.app.Activity;
3534
import android.content.ContentResolver;
3635
import android.content.Context;
3736
import android.net.Uri;
37+
3838
import androidx.annotation.NonNull;
3939

4040
@SuppressWarnings("unused")
@@ -49,9 +49,8 @@ public interface ILogSession {
4949
Context getContext();
5050

5151
/**
52-
* Returns the session {@link Uri}. The Uri may be saved in
53-
* {@link Activity#onSaveInstanceState(android.os.Bundle)} to recreate the session using
54-
* {@link Logger#openSession(Context, Uri)} when orientation change.
52+
* Returns the session {@link Uri}. The Uri may be saved in a saved state
53+
* to recreate the session using {@link Logger#openSession(Context, Uri)} when orientation change.
5554
* Use this Uri also to open the log session in the nRF Logger.
5655
*
5756
* <pre>

log/src/main/java/no/nordicsemi/android/log/LocalLogSession.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import android.content.Context;
3636
import android.net.Uri;
3737
import androidx.annotation.NonNull;
38+
import androidx.annotation.Nullable;
39+
3840
import android.util.Log;
3941

4042
import no.nordicsemi.android.log.localprovider.LocalLogContentProvider;
@@ -67,7 +69,7 @@ public class LocalLogSession implements ILogSession {
6769
*/
6870
public static LocalLogSession newSession(@NonNull final Context context,
6971
@NonNull final Uri authority,
70-
@NonNull final String key, @NonNull final String name) {
72+
@NonNull final String key, @Nullable final String name) {
7173
final Uri uri = authority.buildUpon()
7274
.appendEncodedPath(LogContract.Session.SESSION_CONTENT_DIRECTORY)
7375
.appendEncodedPath(LogContract.Session.KEY_CONTENT_DIRECTORY)

log/src/main/java/no/nordicsemi/android/log/localprovider/LocalLogContentProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public abstract class LocalLogContentProvider extends ContentProvider {
152152
*/
153153
private String mSerializeDbTag;
154154

155-
protected LocalLogDatabaseHelper getDatabaseHelper(final Context context) {
155+
/*package*/LocalLogDatabaseHelper getDatabaseHelper(final Context context) {
156156
return LocalLogDatabaseHelper.getInstance(context);
157157
}
158158

@@ -320,7 +320,7 @@ public int bulkInsert(@NonNull final Uri uri, @NonNull final ContentValues[] val
320320
if (++opCount >= BULK_INSERTS_PER_YIELD_POINT) {
321321
opCount = 0;
322322
try {
323-
yield(transaction);
323+
yieldTransaction(transaction);
324324
} catch (RuntimeException re) {
325325
transaction.markYieldFailed();
326326
throw re;
@@ -358,7 +358,7 @@ public ContentProviderResult[] applyBatch(@NonNull final ArrayList<ContentProvid
358358
if (i > 0 && operation.isYieldAllowed()) {
359359
opCount = 0;
360360
try {
361-
if (yield(transaction)) {
361+
if (yieldTransaction(transaction)) {
362362
ypCount++;
363363
}
364364
} catch (RuntimeException re) {
@@ -579,14 +579,14 @@ private void endTransaction(final Uri uri, final boolean callerIsBatch) {
579579
transaction.finish(callerIsBatch);
580580
} finally {
581581
// No matter what, make sure we clear out the thread-local transaction reference.
582-
mTransactionHolder.set(null);
582+
mTransactionHolder.remove();
583583
}
584584
}
585585
}
586586

587-
protected boolean yield(LogTransaction transaction) {
587+
private boolean yieldTransaction(LogTransaction transaction) {
588588
// Now proceed with the DB yield.
589-
SQLiteDatabase db = transaction.getDbForTag(DB_TAG);
589+
final SQLiteDatabase db = transaction.getDbForTag(DB_TAG);
590590
return db != null && db.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY);
591591
}
592592

log/src/main/java/no/nordicsemi/android/log/localprovider/ProjectionMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
public static class Builder {
4747

48-
private ProjectionMap mMap = new ProjectionMap();
48+
private final ProjectionMap mMap = new ProjectionMap();
4949

5050
Builder add(@NonNull String column) {
5151
mMap.putColumn(column, column);

sample/src/main/java/no/nordicsemi/android/log/example/MainActivity.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
6464

6565
private boolean logProviderExists() {
6666
// The method below requires API 16
67-
final ContentProviderClient unstableClient = getContentResolver()
68-
.acquireUnstableContentProviderClient(LogContract.AUTHORITY);
69-
if (unstableClient == null)
70-
return false;
71-
72-
unstableClient.release();
73-
return true;
67+
try (final ContentProviderClient client = getContentResolver()
68+
.acquireContentProviderClient(LogContract.AUTHORITY)) {
69+
return client != null;
70+
}
7471
}
7572

7673
}

sample/src/main/java/no/nordicsemi/android/log/example/fragment/KeyNameDialogFragment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import android.os.Bundle;
3838
import android.text.TextUtils;
3939
import android.view.KeyEvent;
40-
import android.view.LayoutInflater;
4140
import android.view.View;
4241
import android.view.inputmethod.EditorInfo;
4342
import android.widget.EditText;
@@ -66,7 +65,7 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
6665
.setNegativeButton(android.R.string.no, null)
6766
.setPositiveButton(android.R.string.ok, this);
6867

69-
final View view = LayoutInflater.from(requireContext())
68+
final View view = getLayoutInflater()
7069
.inflate(R.layout.fragment_dialog_key_name, null);
7170
mKeyView = view.findViewById(R.id.key);
7271
mNameView = view.findViewById(R.id.name);

sample/src/main/java/no/nordicsemi/android/log/example/fragment/MainFragment.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import android.content.Intent;
3535
import android.database.Cursor;
3636
import android.net.Uri;
37-
import android.os.Build;
3837
import android.os.Bundle;
3938
import android.view.LayoutInflater;
4039
import android.view.View;
@@ -156,34 +155,32 @@ public View onCreateView(@NonNull final LayoutInflater inflater,
156155
Button openButton = mShowSessionInLoggerButton = rootView.findViewById(R.id.action_open);
157156
openButton.setEnabled(sessionOpen);
158157
openButton.setOnClickListener(v -> {
159-
if (mLogSession != null) {
158+
final Intent intent;
159+
if (mLogSession != null) {
160160
// Open the log session in any app that supports nRF Logger log provider, f.e. in nRF Logger
161-
Intent intent = new Intent(Intent.ACTION_VIEW, mLogSession.getSessionUri());
162-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
163-
startActivity(intent);
164-
} else {
161+
intent = new Intent(Intent.ACTION_VIEW, mLogSession.getSessionUri());
162+
} else {
165163
// nRF Logger is not installed, open the Google Play
166-
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=no.nordicsemi.android.log"));
167-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
168-
startActivity(intent);
169-
}
170-
});
164+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=no.nordicsemi.android.log"));
165+
}
166+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
167+
startActivity(intent);
168+
});
171169

172170
Button openSessionsButton = mShowAllSessionsInLoggerButton = rootView.findViewById(R.id.action_open_sessions);
173171
openSessionsButton.setEnabled(sessionOpen);
174172
openSessionsButton.setOnClickListener(v -> {
175-
if (mLogSession instanceof LogSession) {
173+
final Intent intent;
174+
if (mLogSession instanceof LogSession) {
176175
// Open the sessions in any app that supports nRF Logger log provider, f.e. in nRF Logger
177-
Intent intent = new Intent(Intent.ACTION_VIEW, ((LogSession) mLogSession).getSessionsUri());
178-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
179-
startActivity(intent);
180-
} else {
176+
intent = new Intent(Intent.ACTION_VIEW, ((LogSession) mLogSession).getSessionsUri());
177+
} else {
181178
// nRF Logger is not installed, open the Google Play
182-
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=no.nordicsemi.android.log"));
183-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
184-
startActivity(intent);
185-
}
186-
});
179+
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=no.nordicsemi.android.log"));
180+
}
181+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
182+
startActivity(intent);
183+
});
187184

188185
return rootView;
189186
}
@@ -258,7 +255,7 @@ public void onLoadFinished(@NonNull final Loader<Cursor> loader, @Nullable final
258255

259256
@Override
260257
public void onLoaderReset(@NonNull final Loader<Cursor> loader) {
261-
mLogAdapter.swapCursor(null);
258+
mLogAdapter.changeCursor(null);
262259
}
263260

264261
/**

0 commit comments

Comments
 (0)