
なんか色々あるけど必要か?
「機内」
「マナー」
「サイレント」
「おやすみ」
「エコ」
「省エネ」
「ダーク」
「ナイト」
「開発者」
「デスクトップ」
「セーフ」
それぞれ説明してみようと思いましたが多すぎ。ややこしいわ。知らん。

なんか色々あるけど必要か?
「機内」
「マナー」
「サイレント」
「おやすみ」
「エコ」
「省エネ」
「ダーク」
「ナイト」
「開発者」
「デスクトップ」
「セーフ」
それぞれ説明してみようと思いましたが多すぎ。ややこしいわ。知らん。
Fields cannot be declared directly in Kotlin classes.
Kotlin クラスでは、直接にフィールドを宣言することはできません。
// Kotlin
class Human {
val age = 20
}
// Java
public final class Human {
private final int age = 20;
public final int getAge() {
return this.age;
}
}
ゲッターやセッターにカスタムロジックを入れたい場合は、「バッキング・フィールド」を使うことができます。
カスタムゲッターやセッターのスコープ内で「field」にアクセスできます。
// Kotlin
var counter = 0
set(value) {
if (value >= 0) field = value
}
// Kotlin
class Human {
val age = 20
get() {
println("Age is: $field")
return field
}
}
// Java
public final class Human {
private final int age = 20;
public final int getAge() {
String var1 = "Age is: " + this.age;
System.out.println(var1);
return this.age;
}
}
ゲッターやセッターの外でフィールドに直接アクセスしたいときなどに使います。
private なフィールドに_を付けて明示します。
// Kotlin
private var _table: Map<String, Int>? = null
public val table: Map<String, Int>
get() {
if (_table == null) {
_table = HashMap() // Type parameters are inferred
}
return _table ?: throw AssertionError("Set to null by another thread")
}
// Kotlin
class Human {
private val _age: Int = 20
val age: Int
get() {
return _age
}
val printAge = {
println("Age is: $_age")
}
}
// Java
public final class Human {
private final int _age = 20;
@NotNull
private final Function0 printAge = (Function0)(new Function0() {
public Object invoke() {
this.invoke();
return Unit.INSTANCE;
}
public final void invoke() {
String var1 = "Age is: " + Human.this._age;
System.out.println(var1);
}
});
public final int getAge() {
return this._age;
}
@NotNull
public final Function0 getPrintAge() {
return this.printAge;
}
}
Java にデコンパイルした状況を確認しながら進むと理解しやすいように思います。
👉【Kotlin】Properties and Fields: Getters, Setters
👉 Properties and Fields: Getters, Setters, const, lateinit - Kotlin Programming Language
👉 Backing properties in Kotlin – ProAndroidDev
👉【MVVM】 ViewModel の_プロパティ記述
以下のような nginx などWEBサーバでの鍵の位置指定。
ssl_certificate /etc/letsencrypt/live/android.benigumo.com/fullchain.pem
ssl_certificate_key /etc/letsencrypt/live/android.benigumo.com/privkey.pem
これが、ファイルの実体だと更新時にコケる。
シンボリックリンクでないとならない。
証明書を確認してみると分かる。
# certbot-auto certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Renewal configuration file /etc/letsencrypt/renewal/android.benigumo.com.conf produced an unexpected error: expected /etc/letsencrypt/live/android.benigumo.com/cert.pem to be a symlink. Skipping.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
Certificate Name: android.benigumo.com-0001
Domains: android.benigumo.com
Expiry Date: 2019-07-19 02:41:22+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/android.benigumo.com-0001/fullchain.pem
Private Key Path: /etc/letsencrypt/live/android.benigumo.com-0001/privkey.pem
The following renewal configurations were invalid:
/etc/letsencrypt/renewal/android.benigumo.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
期限の更新できたつもりが、
謎の「0001」な 証明書が追加発行されとる。
# ls -al /etc/letsencrypt/live/android.benigumo.com
drwxr-xr-x 2 ubuntu ubuntu 4096 Mar 1 00:01 .
drwx------ 4 ubuntu ubuntu 4096 Apr 20 12:33 ..
-rw-r--r-- 1 ubuntu ubuntu 2269 Mar 1 00:00 cert.pem
-rw-r--r-- 1 ubuntu ubuntu 1647 Mar 1 00:00 chain.pem
-rw-r--r-- 1 ubuntu ubuntu 3916 Mar 1 00:00 fullchain.pem
-rw-r--r-- 1 ubuntu ubuntu 3272 Mar 1 00:00 privkey.pem
サーバ移行のファイルコピー時に実体化されたっぽい。
シンボリックリンクにする。
複数ある場合は一番新しいものがリンク元となるのが正しい。
# cd /etc/letsencrypt/live/android.benigumo.com/
# rm *
# ln -s ../../archive/android.benigumo.com/cert30.pem cert.pem
# ln -s ../../archive/android.benigumo.com/chain30.pem chain.pem
# ln -s ../../archive/android.benigumo.com/fullchain30.pem fullchain.pem
# ln -s ../../archive/android.benigumo.com/privkey30.pem privkey.pem
# ls -al
lrwxrwxrwx 1 root root 45 Apr 21 08:19 cert.pem -> ../../archive/android.benigumo.com/cert30.pem
lrwxrwxrwx 1 root root 46 Apr 21 08:19 chain.pem -> ../../archive/android.benigumo.com/chain30.pem
lrwxrwxrwx 1 root root 50 Apr 21 08:19 fullchain.pem -> ../../archive/android.benigumo.com/fullchain30.pem
lrwxrwxrwx 1 root root 48 Apr 21 08:19 privkey.pem -> ../../archive/android.benigumo.com/privkey30.pem
追加登録されている0001を削除して期限更新をかける。
# certbot-auto delete --cert-name android.benigumo.com-0001
# certbot-auto renew --dry-run
# certbot-auto renew
# certbot-auto certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
Certificate Name: android.benigumo.com
Domains: android.benigumo.com
Expiry Date: 2019-07-19 22:19:07+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/android.benigumo.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/android.benigumo.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

よし。
Let's Encrypt で '-0001' がついた証明書データを削除する方法 | ラボラジアン
Let's Encrypt(certbot)でrenewしたら"expected /etc/letsencrypt/live/~/cert.pem" | KINの雑記帳
さくらVPSでUbuntu。
「ufw」という簡単でわかりやすいツールがあるんだと。
iptables のラッパーらしいが。
# ufw allow 80
のような操作で、簡単に穴あけできる。
だが、しかし、塞がったままででした。
なにやっても #80アクセスできません。
※ さくらのVPSデフォルト設定であるiptables以外のファイアウォールをご利用になりたい場合は、再起動時に設定が2重に反映されてしまう可能性がありますため、/etc/network/if-pre-up.d/iptables の削除が必要となります。あわせて、iptablesのルール情報である /etc/iptables/iptables.rules も不要となりますため削除いただくこと推奨いたします。
さくらのVPS、スタートアップスクリプト「Ubuntu ufw」を更新しました – さくらのVPSニュース
初期設定では ssh/icmpのみ許可しています。
/etc/network/if-pre-up.d/iptables より、下記設定ファイルを読み込んでおります。
OSセットアップ情報(Ubuntu16.04 LTS) – さくらのサポート情報
さくらのVPS(クラウドも含む可能性があります)のUbuntu 16.04 LTS環境では、2017-12-07現在、netfilter-persistentパッケージをインストールした状態でも設定が上書きされてiptablesのフィルタリング設定が元に戻ってしまう可能性があるようです。
netfilter-persistent が動かないよ @ さくら - Qiita
結局、利用は以下の2つのパターン。
// ufw を使う。 iptables の設定で上書きさせない。
# rm /etc/network/if-pre-upid/iptables
# rm /etc/iptables/iptables.rules
# reboot
# ufw enable
# ufw allow 80
# systemctl enable ufw
// iptables を使う。ufw を無効化。
# iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# iptables-save > /etc/iptables/iptables.rules
# ufw disable
# systemctl disable ufw
# reboot
ufw では届かない設定があるので、ルールの変更は「ufw」と「iptables」コマンドを併用しないほうがよいのだろう。
はまる。
なんとなく面倒なのでスクリプトで。
USBで接続のあと #5555 で待たせて再起動する。
「restart」なので、kill-server → start-server は不要。

adb tcpip 5555
IPアドレスをコマンドラインから取得。
ip="$(adb shell ip route | awk '{print $9}')"
そのIPにWiFi接続。
adb connect $ip
ついでに、開発時には邪魔なスリープもOFFに。
adb shell svc power stayon true
How to prevent an android device from entering sleep (via adb command shell) - Stack Overflow
connect_via_wifi.sh
#!/bin/sh
adb tcpip 5555
sleep 1
ip="$(adb shell ip route | awk '{print $9}')"
adb connect $ip
adb shell svc power stayon true
adb devices -l
端末内 adbd の TCPモード(#5555)が起動している限り再接続が可能。

なので、USB接続なしの状態でも
IPの目処つけて 「adb connect」 でどうぞ。
~ $ adb devices
List of devices attached
~ $ get-oui -v
Renaming ieee-oui.txt to ieee-oui.txt.bak
Fetching OUI data from http://standards-oui.ieee.org/oui/oui.txt
Fetched 4084734 bytes
Opening output file ieee-oui.txt
25968 OUI entries written to file ieee-oui.txt
~ $ sudo arp-scan -l
Interface: en0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9.5 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.0.1 8a:af:ec:9c:91:08 BUFFALO.INC
192.168.0.2 dc:23:76:3d:9b:75 HTC Corporation
192.168.0.3 d0:27:82:f5:e8:2a AzureWave Technology Inc.
192.168.0.8 8c:85:00:14:89:d1 Murata Manufacturing Co., Ltd.
192.168.0.4 a2:37:e3:12:9a:88 HTC Corporation
192.168.0.6 33:28:6d:29:7b:72 Google, Inc.
~ $ adb connect 192.168.0.4
connected to 192.168.0.4:5555
~ $ adb devices
List of devices attached
192.168.0.4:5555 device
初回の、USBケーブルなしでTCPモードを起動できないのはセキュリティ絡みでか。
ADBオーバーネットワークでWiFiで複数端末を一括接続する
Android Devices Being Shipped with TCP Port 5555 Enabled - DEV Community 👩💻👨💻